I have a calculation test and I can’t solve it for hours already.
Here is the scenario:
We imagine an automatic cash that only contains 2 euro coins and 5 euro and 10 euro banknotes.
The quantity of coins and banknotes are unlimited.
So we need an optimal algorithm that can manage the return of change.
This return of change will be expressed in the form of an object with the 3 properties two
, five
and ten
.
If we cannot give change, we would display null
The final method will look like this:
function change(cash){
// logic goes here
return {
two: 0,
five: 0,
ten: 0
}
}
For example, if you have to give change for €42, you would give back 4 notes of 10€ and 1 coin of 2€
So the console.log will looks like:
console.log(change(42).ten) // 4
console.log(change(42).five) // 0
console.log(change(42).two) // 1
Any help will be very appreciate! Thank you very much!