Hex Core JS
    Preparing search index...

    Function mappedArray

    • Creates a new function with a given length, filling the array with elements from a given function taking indices to array elements.

      Type Parameters

      • T

      Parameters

      • length: number

        length of the new Array

      • filler: (index: number) => T

        function taking indices to array elements

      Returns T[]

      an array filled with the mapped values

      mappedArray(5, (n) => n * n);
      // returns
      [0, 1, 4, 9, 16]
      // Instead of
      new Array(5).fill(null).map((_, i) => ...);
      // do
      mappedArray(5, (i) => ...);
      mappedArray(5, () => "value");
      // effectively equivalent to
      new Array(5).fill("value");