Ajouter tous les éléments de la table javascript
console.log(
[1, 2, 3, 4].reduce((a, b) => a + b, 0)
)
console.log(
[].reduce((a, b) => a + b, 0)
)
Clean Constrictor
console.log(
[1, 2, 3, 4].reduce((a, b) => a + b, 0)
)
console.log(
[].reduce((a, b) => a + b, 0)
)
console.log(
[].reduce((a, b) => a + b)
)
function getArraySum(a){
var total=0;
for(var i in a) {
total += a[i];
}
return total;
}
var payChecks = [123,155,134, 205, 105];
var weeklyPay= getArraySum(payChecks); //sums up to 722
const years = [1, 2, 3, 4]
let total = 0;
for (let i = 0; i < years.length; i++) {
total += years[i]
}
console.log(total)
//answer willl be 10