Logos DX
    Preparing search index...

    Function nTimes

    • Repeats something N times and returns an array of the results.

      Type Parameters

      • T

      Parameters

      • fn: (iteration: number) => T

        function to repeat

      • n: number

        number of times to repeat

      Returns T[]

      array of results

      nTimes(() => createEl('span'), 3) // [span, span, span]
      nTimes(() => Math.random(), 5) // [0.123, 0.456, 0.789, 0.123, 0.456]
      nTimes((i) => (i + 1) * 2, 3) // [2, 4, 6]