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

Friday, December 16, 2016

Codefights rounders(value)


//sample solution
function rounders(value) {
var valueArrayed = value.toString().split("").reverse();
    //document.writeln("valueArrayed: ", valueArrayed, "<br/>");
    //document.writeln("valueArrayed length: ", valueArrayed.length, "<br/>");
    for(i=0;i<valueArrayed.length;i++){
    var temp=valueArrayed[i];
        if(temp>=5 && i!=valueArrayed.length-1){
        valueArrayed[i]=0;
            valueArrayed[i+1]++;
        } else if(i!=valueArrayed.length-1){
        valueArrayed[i]=0;
        }
    }
    //document.writeln("valueArrayed: ", valueArrayed, "<br/>");
    return parseInt(valueArrayed.reverse().join(""));
}

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts