Which fix removes the bug?
const total = items.reduce((sum, i) => sum + i.price);
- Give reduce a seed of 0
- Map to prices first
- Use forEach and a sum
- Check items is not empty
Without an initial value the first element becomes sum, so an object is added to a number.
Play Problem Solving ▸