• Repeats a function n times and returns an array of the results.

    The function executes the provided callback for each iteration, passing the current index and the total count as arguments. It collects and returns the results of the callback in an array.

    Example

    const result = times((index, count) => index / count, 5);
    // => [0, 0.2, 0.4, 0.6, 0.8]

    Example

    const repeatedStrings = times(() => 'hello', 3);
    // => ['hello', 'hello', 'hello']

    Type Parameters

    • T

    Parameters

    • callback: ((index, count) => T)

      The function to be called on each iteration. Receives the current index and the total count.

        • (index, count): T
        • Parameters

          • index: number
          • count: number

          Returns T

    • count: number

      The number of times to execute the callback.

    Returns T[]