Can someone explain to me how this code works, or a link to somewhere that explains this? (specifically the part: +acc + +curr; )
Code in question:
let args = process.argv;
let sum = args.reduce(function(acc, curr) {
return +acc + +curr;
});
console.log(sum);
Original solution with for-loop that does the same thing:
let result = 0;
for (i = 0; i < process.argv.length; i++) {
result += Number(process.argv[i])
}
console.log(result);
Is the fancy code on top a good method to know / recommended practice? Thanks.