Creates a new function with a given length, filling the array with elements from a given function taking indices to array elements.
length of the new Array
function taking indices to array elements
an array filled with the mapped values
mappedArray(5, (n) => n * n);// returns[0, 1, 4, 9, 16] Copy
mappedArray(5, (n) => n * n);// returns[0, 1, 4, 9, 16]
// Instead ofnew Array(5).fill(null).map((_, i) => ...);// domappedArray(5, (i) => ...); Copy
// Instead ofnew Array(5).fill(null).map((_, i) => ...);// domappedArray(5, (i) => ...);
mappedArray(5, () => "value");// effectively equivalent tonew Array(5).fill("value"); Copy
mappedArray(5, () => "value");// effectively equivalent tonew Array(5).fill("value");
Creates a new function with a given length, filling the array with elements from a given function taking indices to array elements.