I’m wondering why this code changes BOTH newCID and cid? Can anyone help to explain? Thanks!
Edit: This is the JavaScript Algorithms and Data Structures Projects: Cash Register. I don’t
var cid = [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]];
var newCID = cid.concat();
var registerValues = origCID.reverse().map(function(item) {
item[1] = item[1] / monetaryValues[count];
count += 1;
return Math.round(item[1]);
});
When I run my program, both arrays turn into:
//cid (the original is now)
PENNY,101,NICKEL,40.99999999999999,DIME,31,QUARTER,17,ONE,90,FIVE,11,TEN,2,TWENTY,3,ONE HUNDRED,1
ONE
//newCID is now
HUNDRED,1,TWENTY,3,TEN,2,FIVE,11,ONE,90,QUARTER,17,DIME,31,NICKEL,40.99999999999999,PENNY,101
However, I’d like to keep one original version and just modify the copy.
Edit: Including more information