Created
July 12, 2023 17:42
-
-
Save pedrotnascimento/ed36a640afc0a9974adf3a80b4ea990e to your computer and use it in GitHub Desktop.
Change counting interview for CI&T
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 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