ramonchang

ol

Oct 27th, 2020
792
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const checkCashRegister = function(price, paid, register){
  2.     const currencies = [
  3.         ["PENNY", 0.01],
  4.         ["NICKEL", 0.05],
  5.         ["DIME", 0.1],
  6.         ["QUARTER", 0.25],
  7.         ["ONE", 1],
  8.         ["FIVE", 5],
  9.         ["TEN", 10],
  10.         ["TWENTY", 20],
  11.         ["ONE HUNDRED", 100]
  12.       ]
  13.  
  14.     const remainder = paid - price
  15.     let diff = remainder
  16.     if(remainder <= 0 ){
  17.         return {status: "INSUFF FUNDS", change:[]}
  18.     } else {
  19.         const v = currencies.reverse().map(function(currency, i){
  20.             if (diff >= currency[1]){
  21.                 var n = Math.floor(diff / currency[1])
  22.                 var rem = diff % currency[1]
  23.             } else {
  24.                 var n = 0
  25.                 var rem = diff
  26.             }
  27.             // console.log(val)
  28.             diff = rem == undefined ? diff : rem
  29.             return [currency[0], rem, n*currency[1], n]
  30.         })
  31.         console.log(v)
  32.     }
  33.  
  34. }
  35.  
  36. checkCashRegister(19, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]])
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×