$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · medium · #183

Which fix removes the bug?

const total = items.reduce((sum, i) => sum + i.price);
  1. Give reduce a seed of 0
  2. Map to prices first
  3. Use forEach and a sum
  4. 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 ▸