Function pingPong

Ping-pongs continually back and forth a lower and upper value (both inclusive) by a given interval. Use pingPongPercent for 0-1 ping-ponging

In a loop:

for (const c of pingPong(10, 0, 100)) {
// 0, 10, 20 .. 100, 90, 80, 70 ...
}

Manual:

const pp = pingPong(10, 0, 100);
let v = pp.next().value; // Call .next().value whenever a new value is needed
  • Parameters

    • interval: number

      Amount to increment by. Use negative numbers to start counting down

    • lower: number

      Lower bound (inclusive)

    • upper: number

      Upper bound (inclusive, must be greater than start)

    • Optionalstart: number

      Starting point within bounds (defaults to lower)

    • Optionalrounding: number

      Rounding is off by default. Use say 1000 if interval is a fractional amount to avoid rounding errors.

    Returns Generator<number, never, unknown>