I have a simple task. I've got to do an ATM in javascript. However, I don't know, how whether add 1 to an object if exists or if counting object duplicates and then showing them.
This is my main function.
const getCash = (credit, saved) => {
let returnedCash = []
for (const obj of saved) {
for (let i = 0; i < obj.amount; i++) {
if (credit > 0){
if (credit - obj.value < 0) break
credit -= obj.value
returnedCash.push({value: obj.value})
}
}
}
return returnedCash
}
And then returns something like this
[{value: 50}, {value: 50}, {value: 30}]
Know how to do both? And what is more a good practice?