Quotes help make search much faster. Example: "Practice Makes Perfect"

Friday, December 16, 2016

Codefights candles(candlesNumber, makeNew)


//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


This is an example of scrolling text using Javascript.

Popular Posts