Advertisement
VanoHa

sum

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