Skip to content

Instantly share code, notes, and snippets.

@squalvj
Created September 30, 2018 05:09
Show Gist options
  • Save squalvj/1d27b83931f17456e0e5582216997ad4 to your computer and use it in GitHub Desktop.
Save squalvj/1d27b83931f17456e0e5582216997ad4 to your computer and use it in GitHub Desktop.
Coin Change Problem using greedy algorithm
var makeChange = function(amount) {
var change = [],
total = 0;
[25, 10, 5, 1].forEach(function(coin) {
while (total + coin <= amount) {
change.push(coin);
total += coin;
}
});
return change;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment