JSFiddle - React, Tailwind, and code Playground
by nimishgoel056
JavaScript
function withdraw(amount) {
// coding and coding..
let amtArray = [100, 50, 20];
let notes = [];
if(amount >= 40 && amount <= 1000 ) {
if(amount%50 == 0) {
for (let i = 0; i < amtArray.length; i++) {
notes.push(Math.floor(amount / amtArray[i]));
// Get the new total
amount = amount % amtArray[i];
}
} else {
debugger;
//for (let i = 0; i < amtArray.length; i++) {
notes.push(Math.floor(amount / 100));
// Get the new total
amount = amount % 100; // 80
if(amount >= 50) {
if((amount / 10)%2 == 0) {
notes.push(0);
notes.push(Math.floor(amount / 20));
amount = amount % 20;
} else {
notes.push(Math.floor(amount / 50));
amount = amount % 50;
notes.push(Math.floor(amount / 20));
amount = amount % 20;
}
}
else {
notes.push(0);
notes.push(Math.floor(amount / 20));
amount = amount % 20;
}
// }
}
return notes;
}
}
withdraw(260);