Created
February 13, 2022 06:58
-
-
Save tamunoibi/d16c6d2ba7aa39136b4098d95f07d0c4 to your computer and use it in GitHub Desktop.
This is an incomplete attempt at solving the cash register freecodecamp problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function checkCashRegister(price, cash, cid) { | |
let change = cash - price; | |
let total = 0; | |
let totalCID = cid.forEach((item) => { | |
total += item[1] | |
}); | |
console.log(total); | |
if(total < change) { | |
return {status: "INSUFFICIENT_FUNDS", change: []}; | |
} | |
if(change === total) { | |
return {status: "CLOSED", change: cid}; | |
} | |
if(total > change) { | |
let newChange = []; | |
cid.reverse().forEach((elem) => { | |
while(change >= elem[1]) { | |
var quo = Math.floor( elem[1] / change); | |
change === (change - (elem[1] * quo)); | |
newChange.push([elem[0], elem[1]]) | |
} | |
}); | |
return {status: "OPEN", 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]]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment