Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function isEven(x, y) {
- return x % 2 === 0
- }
- function filter(arr, callback) {
- const reducer = function (acc, x, i) {
- if (callback(x, i, arr)) // look here
- acc.push(x)
- return acc
- }
- const initialValue = []
- return arr.reduce(reducer, initialValue)
- }
- const xs = [1, 2, 3, 4, 5]
- const evens = filter(xs, isEven)
- console.log(evens)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement