An array reduction applies a callback to successive values to produce one result. Use `reduce` when a function receives any number of values but must return one total. A rest parameter collects the arguments into an array; `reduce` then accumulates them. section 3.3.3
Sum a variable number of prices
In `primer/index.js`: ```js function sumPrices(...numbers) { return numbers.reduce((total, val) => total + val, 0); } console.log(sumPrices(100, 200, 300)); // 600 console.log(sumPrices(100, "100")); // "100100" ``` The callback receives the accumulated total and the next value; `0` supplies the starting total. The second call concatenates because the addition operator encounters a string. Changing the number of arguments does not fix that type problem. section 3.3.3
Convert values before adding them
To keep the total numeric, convert each value and substitute zero when conversion produces `NaN`: ```js function sumPrices(...numbers) { return numbers.reduce((total, val) => total + (Number.isNaN(Number(val)) ? 0 : Number(val)), 0); } console.log(sumPrices(100, "100")); // 200 console.log(sumPrices(100, 200, undefined, false, "hello")); // 300 ``` Here `false` converts to zero; `undefined` and `"hello"` produce `NaN` and contribute zero. The arrow function is a shorter way to write the callback. section 3.3.3
An array’s `reduce` method is distinct from a Redux reducer. A Redux reducer is a function used to modify data-store state, not a call that folds array elements into one value. section 3.3.3 section 20.5








