**Hello everyone,
I’d need to clarify the code that converts an array into object (code bellow). I get how it works…sort of, but my understanding of it is less than crystally clear.
For example, what exactly parameters function(acc, curr)
refer to?
Furthermore, why is it coded acc[curr[0]] = curr[1];
?
Should it not be acc[curr[1]] = curr[1];
?
Help is much appreciated.
**
Your code so far
// Create an array of objects which hold the denominations and their values
... this part is clear....
// questions refer to the part bellow
function checkCashRegister(price, cash, cid) {
var output = { status: null, change: [ ] };
var change = cash - price;
// Transform CID array into drawer object
var register = cid.reduce(
function(acc, curr) {
acc.total += curr[1];
acc[curr[0]] = curr[1];
return acc;
},
{ total: 0 }
);
//.... code goes on...
function checkCashRegister(price, cash, cid) {
var change;
return change;
}
checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36
.
Challenge: Cash Register
Link to the challenge: