This challenge doesn’t need more than simple array processing to complete. The most complicated data structure required is an array. The harder part of it is formulating an algorithm (not coding it), and figuring out of which data you need to keep track. For example, you weren’t initially keeping track of how much change you had already made, but there is no way to do it without that. Now you have
You need two things to arrive at a passable solution:
- Fix the sum assignment.
- Remove unnecessary loops.
If you haven’t run my fiddle linked above yet, do it. Read the console, and you’ll see what I mean.