Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

rounders javascript

function solution(n) {
    let num = n.toString().split('');
    let i = num.length - 1;
    while (i > 0) {
        if (num[i] >= 5) {
            num[i - 1] = (parseInt(num[i - 1]) + 1).toString();
        }
        num[i] = '0';
        i--;
    }
    return parseInt(num.join(''));
}
 
PREVIOUS NEXT
Tagged: #rounders #javascript
ADD COMMENT
Topic
Name
4+7 =