Function everyNth

Returns true for every _n_th call, eg 2 for every second call.

If nth is 1, returns true for everything. 0 will be false for everything.

Usage:

const tenth = everyNth(10);
window.addEventListener(`pointermove`, evt => {
if (!tenth(evt)) return; // Filter out
// Continue processing, it is the 10th thing.

});

Alternative:

window.addEventListener(`pointermove`, everyNth(10, evt => {
// Do something with tenth item...
});
  • Type Parameters

    • T

    Parameters

    • nth: number

      Every nth item

    • Optionalcallback: ((data: T) => void)
        • (data): void
        • Parameters

          • data: T

          Returns void

    Returns ((data: T) => boolean)

    Function which in turn returns true if nth call has been hit, false otherwise

      • (data): boolean
      • Parameters

        • data: T

        Returns boolean