Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const array1 = [1, 2, 3, 4];
- // 0 + 1 + 2 + 3 + 4
- const initialValue = 0;
- const sumWithInitial = array1.reduce(
- (accumulator, currentValue) => accumulator + currentValue,
- initialValue,
- );
- console.log(sumWithInitial);
- // Expected output: 10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement