Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pedrotnascimento/ed36a640afc0a9974adf3a80b4ea990e to your computer and use it in GitHub Desktop.
Save pedrotnascimento/ed36a640afc0a9974adf3a80b4ea990e to your computer and use it in GitHub Desktop.
Change counting interview for CI&T
const coins = [100,20,5]
class Counter {
name: string;
// Coin values: 100, 20, 5
// 25 => 20 +5
constructor(name: string) {
this.name = name;
}
getCoins(amount) {
var ret =[]
let remaining = amount;
for ( var i =0; i < coins.length; ){
if(remaining%coins[i]==0){
ret.push(coins[i]);
}
else{
i++;
continue;
}
remaining = remaining - coins[i];
console.log(remaining)
if(remaining ==0){
return ret;
}
}
}
}
const c = new Counter("Ye Olde Shop");
console.log(c.getCoins(95));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment