Spot the bug in this snippet.
const prices = [10, 20, 30];
const total = prices.reduce((sum, p) => {
sum + p;
}, 0);
console.log(total);
Reply with what is broken and how you would fix it.
Arthur
Spot the bug in this snippet.
const prices = [10, 20, 30];
const total = prices.reduce((sum, p) => {
sum + p;
}, 0);
console.log(total);
Reply with what is broken and how you would fix it.
Arthur
In your snippet the reducer has braces but doesn’t return anything, so total ends up wrong (you’ll get 0 here because you passed an initial value of 0) — did you mean to return sum + p from the callback? I might be wrong here.
:: Copyright KIRUPA 2024 //--