Skip to content

Instantly share code, notes, and snippets.

View gax97's full-sized avatar
🏠
Working from home

Danilo Gačević gax97

🏠
Working from home
View GitHub Profile
<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>