This is an early step in the Cash Register Challenge at Free Code Camp, I think I’ve got ahead of the curriculm a bit, but I was also hoping most of it would be review. I thought I could start preplanning my projects with psuedo code.
I’m just trying to make a variable that would take the 2nd property of the array and sum a total to represent how much is in the drawer at the moment
let 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 totalINdrawer = [cid]; //reduce the 2nd property of an arrary
var myData = reduce.cid[i][1];
console.log(myData);
…that returns $335.40999999999997? The cents should add up to .41 I guess it’s some sort of rounding error since we’re already operating behind the decimal. Should I just round it up? Or should I try to correct for it somewhere sooner in the process? I’d like to understand more about where the anomaly starts… If I started by multiplying them all by 100 then divided afterwords, would that correct for it? Or is that most likely what it’s already doing and where the anomaly starts at?
This link implies I was on the correct path. I should probably multiply all the cents by 100 to be working with whole numbers, I should probably do that in the mapping phase before the reduction takes place.