2634. Filter Elements from Array ¶ TypeScript 1 2 3 4 5 6 7 8 9 10 11type Fn = (n: number, i: number) => any; function filter(arr: number[], fn: Fn): number[] { const ans: number[] = []; arr.forEach((a, index) => { if (fn(a, index)) { ans.push(a); } }); return ans; }