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

Stats:

CreatedOct 14, 2021
Warriors Trained16
Total Skips0
Total Code Submissions24
Total Times Completed15
JavaScript Completions15
Total Stars0
% of votes with a positive feedback rating25% of 12
Total "Very Satisfied" Votes2
Total "Somewhat Satisfied" Votes2
Total "Not Satisfied" Votes8
Total Rank Assessments12
Average Assessed Rank
7 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • TheodoreLefrancois Avatar
Ad