nikolayneykov

Untitled

Nov 7th, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
  2.  
  3. const reduce = (array, fn, initialValue) => {
  4.   let accumolator = initialValue;
  5.  
  6.   for (let i = 0; i < array.length; i++) {
  7.     accumolator = fn(accumolator, array[i]);
  8.   }
  9.  
  10.   return accumolator;
  11. };
  12.  
  13. const sum = reduce(arr, (a, b) => a + b, 0);
  14.  
  15. console.log(sum);
Advertisement
Add Comment
Please, Sign In to add comment