Skip to content

Instantly share code, notes, and snippets.

@scolton99
Created May 1, 2022 02:59
Show Gist options
  • Save scolton99/65d68650f9b048210f2e36bf358abe41 to your computer and use it in GitHub Desktop.
Save scolton99/65d68650f9b048210f2e36bf358abe41 to your computer and use it in GitHub Desktop.
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