Skip to content

Instantly share code, notes, and snippets.

@nimamehanian
Created February 13, 2018 09:53
Show Gist options
  • Save nimamehanian/aeff491bfd35e53c1cc1bbfd668d84dc to your computer and use it in GitHub Desktop.
Save nimamehanian/aeff491bfd35e53c1cc1bbfd668d84dc to your computer and use it in GitHub Desktop.
Change-making problem
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