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 reduce = (array, fn, initialValue) => {
- let accumolator = initialValue;
- for (let i = 0; i < array.length; i++) {
- accumolator = fn(accumolator, array[i]);
- }
- return accumolator;
- };
- const sum = reduce(arr, (a, b) => a + b, 0);
- console.log(sum);
Advertisement
Add Comment
Please, Sign In to add comment