Created
February 13, 2018 09:53
-
-
Save nimamehanian/aeff491bfd35e53c1cc1bbfd668d84dc to your computer and use it in GitHub Desktop.
Change-making problem
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 makeChange = (tier, divisors) => { | |
if (!tier.length) { return false; } | |
const nextTier = tier.reduce((t, n) => | |
[...t, ...divisors.map(div => n - div)], [] | |
).filter(val => val > -1); | |
return nextTier.indexOf(0) === -1 ? | |
makeChange(nextTier, divisors) : true; | |
}; | |
makeChange([10], [3, 4]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment