Skip to content

Instantly share code, notes, and snippets.

@gax97
Created November 2, 2020 14:01
Show Gist options
  • Save gax97/3f742d075f1ec7963ad0ccbb207c6db1 to your computer and use it in GitHub Desktop.
Save gax97/3f742d075f1ec7963ad0ccbb207c6db1 to your computer and use it in GitHub Desktop.
<input id="input"/>
<button id="button">retrieve</button>
<script>
const apoens = [5000, 2000, 1000, 500, 200, 100, 50, 20, 10];
const getMoney = (money, apoens, returnarray) => (money === 0 || apoens.length === 0) ? returnarray : (money < apoens[0] ? (apoens.shift(), getMoney(money, apoens, returnarray)) : (returnarray.push(apoens[0]), getMoney(money - apoens[0], apoens, returnarray)));
document.getElementById("button").addEventListener('click', (event)=> {
let value = document.getElementById("input").value;
console.log(getMoney(Number(value), apoens, []))
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment