//sample solution
function candles(candlesNumber, makeNew) {
var newCandles=candlesNumber;
var newlyBurnedCandles=0;
var leftoverCandles=0;
var totalBurnedCandles=0;
while(newCandles>0){
//burn
newlyBurnedCandles = newCandles;
totalBurnedCandles = totalBurnedCandles + newlyBurnedCandles;
leftoverCandles = leftoverCandles + newlyBurnedCandles;
//create
var temp = Math.floor(leftoverCandles/makeNew);
newCandles = temp;
leftoverCandles = leftoverCandles % makeNew;
}
return totalBurnedCandles;
}
No comments:
Post a Comment