Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

reduce method

function reduce(array, combine, start) {
  let current = start;
  for (let element of array) {
    current = combine(current, element);
  }
  return current;
}

console.log(reduce([1, 2, 3, 4], (a, b) => a + b, 0));
// → 10
Source by eloquentjavascript.net #
 
PREVIOUS NEXT
Tagged: #reduce #method
ADD COMMENT
Topic
Name
2+9 =