I'm wondering if there are any benefits for using reduce over the for loop. (except for it's shorter)
Let's take, for example, the sum function.
function sum(arr) {
return arr.reduce((acc, current) => acc + current, 0);
}
Or with for.
function sum(arr) {
let total = 0;
for (let i = 0; i < arr.length; i++){
total += arr[i];
}
return total;
}