Created
May 1, 2022 02:59
-
-
Save scolton99/65d68650f9b048210f2e36bf358abe41 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const COINS = { | |
25: 'QUARTER', | |
10: 'DIME', | |
5: 'NICKEL', | |
1: 'PENNY' | |
}; | |
const COIN_VALUES = Object.keys(COINS).sort((a, b) => b - a); | |
class LL { | |
v = null; | |
n = null; | |
constructor(v, n) { | |
this.v = v; | |
this.n = n; | |
} | |
} | |
const printList = ll => { | |
const internal = ll => { | |
if (ll === null) | |
return ''; | |
return `${ll.v}, ${internal(ll.n)}` | |
}; | |
console.log(internal(ll)); | |
} | |
const makeChange = cents => { | |
if (cents === 0) | |
return null; | |
for (const val of COIN_VALUES) | |
if (val <= cents) | |
return new LL(val, makeChange(cents - val)); | |
}; | |
printList(makeChange(73)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment