Answers for "reduce en javascript"

90

javascript reduce

var array = [36, 25, 6, 15];

array.reduce(function(accumulator, currentValue) {
  return accumulator + currentValue;
}, 0); // 36 + 25 + 6 + 15 = 82
Posted by: Guest on May-21-2020
0

javascript reduce

You can return whatever you want from reduce method, reduce array method good for computational problems
const arr = [36, 25, 6, 15];
array.reduce(function(accumulator, currentValue) {
  return accumulator + currentValue;
}, 0); // this will return Number
array.reduce(function(accumulator, currentValue) {
  return accumulator + currentValue;
}, []); // this will return array
let {total} = array.reduce(function(accumulator, currentValue) {
  let {currentVal} = currentValue
  return accumulator + currentVal;
}, {
total: 0
}); // this will return object
And one additional rule is always always retrun the first param, which do arithmetic operations.
Posted by: Guest on January-13-2022
0

reduce method

[0, 1, 2, 3, 4].reduce(
  (accumulateur, valeurCourante) => accumulateur + valeurCourante;
);
Posted by: Guest on March-19-2022

Code answers related to "Javascript"

Browse Popular Code Answers by Language