I'm currently creating a JavaScript cash register application that calculates the exact change based on the available funds in the register. This project is part of a challenge on freeCodeCamp: https://www.freecodecamp.org/challenges/exact-change
Although I've made progress, I've hit a roadblock.
The key function in my program is addResult()
, which accepts two parameters: name
and val
.
var result = [];
function addResult(name, val){
result.push([name, val]);
}
For instance, if an $18 change is required, the function constructs an array like this:
[["ONE", 1.00], ["ONE", 1.00], ["ONE", 1.00], ["FIVE", 5.00], ["TEN", 10.00]]
However, I want the resulting array to look like this instead:
[["ONE", 3.00], ["FIVE", 5.00], ["TEN", 10.00]]
My goal is to have unique string names but aggregate the numbers together, yet I can't seem to figure out how to achieve this.
If anyone is willing to examine the complete code, here it is:
...