2634. Filter Elements from Array
https://leetcode.com/problems/filter-elements-from-array
Javascript
var filter = function(arr, fn) {
let result = []
for (let i=0; i < arr.length; i++) {
if (fn(arr[i], i)) {
result.push(arr[i])
}
}
return result
};
Typescript
function filter(arr: number[], fn: (n: number, i: number) => any): number[] {
let result = []
for (let i=0; i < arr.length; i++) {
if (fn(arr[i], i)) {
result.push(arr[i])
}
}
return result
};