Retired
Give change (retired)
Description:
Imagine to be at the supermarket checkout and the cashier has to give you back a certain amount of money
TASK:
You have to create a function GiveChange which will take a an amount of money as parameter
The function should return an Array with the same length as the Array COINS .
COINS = [1, 2, 5, 10, 20, 50, 100, 200, 500]
The array COINS is corresponding to all the differents amount of units available for €
This array should be filled with amount required of each type of value. But it should be done in such a way that the sum of the number of each value should be as low as possible. Here is a not valid example:
console.log(GiveChange(258))
// should not return [258, 0, 0, 0, 0, 0, 0, 0, 0] because
1*258 + 2*0 + 5*0 + 10*0 + 20*0 + 50*0 + 100*0 + 200*0 + 500*0 = 258
// but you could use 1*200€ banknote instead of 200*1€ coins
Here is valid example:
console.log(GiveChange(258))
// should return [1, 1, 1, 0, 0, 1, 0, 1, 0] because
1*1 + 2*1 + 5*1 + 10*0 + 20*0 + 50*1 + 100*0 + 200*1 + 500*0 = 258
// according the the Array COINS [1, 2, 5, 10, 20, 50, 100, 200, 500]
Dont' worry during the tests, all the inputs will be positives and
0<amount<10000
Fundamentals
Similar Kata:
Stats:
Created | Oct 14, 2021 |
Warriors Trained | 16 |
Total Skips | 0 |
Total Code Submissions | 24 |
Total Times Completed | 15 |
JavaScript Completions | 15 |
Total Stars | 0 |
% of votes with a positive feedback rating | 25% of 12 |
Total "Very Satisfied" Votes | 2 |
Total "Somewhat Satisfied" Votes | 2 |
Total "Not Satisfied" Votes | 8 |
Total Rank Assessments | 12 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 8 kyu |