Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. ```javascript
  2. function reduce(array, callback, initialValue) {
  3. let accumulator = initialValue;
  4. for (let i = 0; i < array.length; i++) {
  5. accumulator = callback(accumulator, array[i]);
  6. }
  7. return accumulator;
  8. }
  9. // Uncomment these to check your work!
  10. const nums = [4, 1, 3];
  11. const add = function(a, b) { return a + b; }
  12. console.log(reduce(nums, add, 0)); // should log 8
  13. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement