-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
changeMe.js
13 lines (8 loc) · 1022 Bytes
/
changeMe.js
1
2
3
4
5
6
7
8
9
10
11
12
13
/*
Your task is to create a change machine.
The machine accepts a range of specified coins and notes, it returns change in 20p and 10p coins in the minimum amount of pieces. A 50p for example would return two 20p pieces and one 10p piece. The machine will always try and return change, if you input a 20p for example it will return "10p 10p".
The machine accepts these coins and notes: £5, £2, £1, 50p, 20p. Any coins and notes which are not accepted by the machine will be returned. If you were to put a £20 note into the machine for example, it would be returned to you and not broken into change.
This change machine is programmed to accept and distribute strings rather than numbers. The change will be returned as one string with the change separated by single spaces & no commas. The values of the string will be descending.
*/
//Answer//
let changeMe = m => m==='£5'?'20p '.repeat(25).trim():m==='£2'?'20p '.repeat(10).trim():m==='£1'?'20p 20p 20p 20p 20p':m==='50p'?'20p 20p 10p':m==='20p'?'10p 10p':m