Creates a function that only invokes the provided callback every Nth time it's called.
The function to be conditionally executed.
The number of calls between each execution. Must be ≥ 1.
A new function that tracks call count and only invokes fn every Nth time.
fn
Will throw an error if n is less than 1 or not an integer.
n
// ES Moduleimport { everyNthCall } from 'your-library/timing';// CommonJSconst { everyNthCall } = require('your-library/timing'); Copy
// ES Moduleimport { everyNthCall } from 'your-library/timing';// CommonJSconst { everyNthCall } = require('your-library/timing');
const logEvery3 = everyNthCall(() => console.log("called"), 3);logEvery3() // nothinglogEvery3() // nothinglogEvery3() // logs "called" Copy
const logEvery3 = everyNthCall(() => console.log("called"), 3);logEvery3() // nothinglogEvery3() // nothinglogEvery3() // logs "called"
Creates a function that only invokes the provided callback every Nth time it's called.