Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. function isEven(x, y) {
  2. return x % 2 === 0
  3. }
  4.  
  5. function filter(arr, callback) {
  6. const reducer = function (acc, x, i) {
  7. if (callback(x, i, arr)) // look here
  8. acc.push(x)
  9. return acc
  10. }
  11. const initialValue = []
  12.  
  13. return arr.reduce(reducer, initialValue)
  14. }
  15.  
  16. const xs = [1, 2, 3, 4, 5]
  17. const evens = filter(xs, isEven)
  18.  
  19. console.log(evens)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement