JS Soma de Array
[1, 2, 3, 4].reduce((a, b) => a + b, 0)
// Output: 10
stdafx-h
[1, 2, 3, 4].reduce((a, b) => a + b, 0)
// Output: 10
let flattened = [[0, 1], [2, 3], [4, 5]].reduce(
function(accumulator, currentValue) {
return accumulator.concat(currentValue)
},
[]
)
// flattened is [0, 1, 2, 3, 4, 5]
const sum = arr => arr.reduce((a, b) => a + b, 0);
var objs = [
{name: "Peter", age: 35},
{name: "John", age: 27},
{name: "Jake", age: 28}
];
objs.reduce(function(accumulator, currentValue) {
return accumulator + currentValue.age;
}, 0); // 35 + 27 + 28 = 90
let array = [36, 25, 6, 15];
array.reduce((acc, curr) => acc + curr, 0)
// 36 + 25 + 6 + 15 = 82
reduce function sample solution