Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
- const filter = (array, fn) => {
- const newArr = [];
- for (let i = 0; i < array.length; i++) {
- if (fn(array[i])) {
- newArr.push(array[i]);
- }
- }
- return newArr;
- };
- const evenNumbers = filter(arr, (num) => num % 2 === 0);
- console.log(evenNumbers);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement