stepByStep()

Performs a callback function with the ability to decide when to move to the next step of the range

Range.prototype.stepByStep()

The stepByStep() method performs a callback function with the ability to decide when to move to the next step of the range.

range.class.ts
public stepByStep(
  callbackFn: (value: Generator<number>, step: Step, max: Max) => void
): this {
  const t = this;
  callbackFn(
    (function* stepByStep(current = t.min - t.step): Generator<number> {
      while (current < t.max) {
        yield (current += t.step);
      }
    })(),
    t.step,
    t.max
  );
  return this;
}

Parameters

callbackFn: (value:Generator<number>, step:Step, max:Max) => void

A function that accepts up to three arguments. The value is a function generator that allows deciding when to move to the next step, step is the step, and max is the maximum of a specified Range object.

value:Generator<number> - Function generator allows deciding when to move to the next range step. step:Step - The step of a specified Range object. max:Max - The maximum range of a specified Range object.

Return type

Returns

The return value is the Range instance.

Example usage

Last updated