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