Created
November 2, 2020 14:01
-
-
Save gax97/3f742d075f1ec7963ad0ccbb207c6db1 to your computer and use it in GitHub Desktop.
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
<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