Created
March 23, 2017 16:56
-
-
Save abdalla/c0f5ec0136bca695c08ffc79a5a68fcf to your computer and use it in GitHub Desktop.
enjoy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const typesOfCoins = [25, 10, 5, 1]; | |
const exchange = vl => { | |
let exchanges = []; | |
typesOfCoins.reduce((cur, next) => { | |
const val = Math.floor(cur/next); | |
const rest = cur - (val * next); | |
exchanges.push(val); | |
return (exchanges, rest); | |
}, vl); | |
return exchanges; | |
} | |
console.log(exchange(106)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment