1const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
2
3const filter = arr.filter((number) => number > 5);
4console.log(filter); // [6, 7, 8, 9]
5
1// filter takes an array and function as argumentfunction
2filter(arr, filterFunc) {
3 const filterArr = []; // empty array
4 // loop though array
5 for(let i=0;i<arr.length;i++) {
6 const result = filterFunc(arr[i], i, arr);
7 // push the current element if result is true
8 if(result)
9 filterArr.push(arr[i]);
10 }
11 return filterArr;
12}