Skip to content

2635. Apply Transform Over Each Element in Array 👍

1
2
3
4
5
6
7
function map(arr: number[], fn: (n: number, i: number) => number): number[] {
  const ans: number[] = [];
  arr.forEach((a, index) => {
    ans.push(fn(a, index));
  });
  return ans;
}