re: Daily Coding Puzzles - Oct 29th - Nov 2nd VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Wednesday Write a program to reverse the digits of a positive integer but without converting it to a string.
 

probably not the best solution but it works. (unless you want leading zeros...but I'm assuming that's not the case since it wants a number).

function reverseNum(n) {
    const divisor = 10;
    let reversed = 0;
    let holder = [];
    while(n > 0) {
        holder.push(n % divisor);
        n = (Math.floor(n / divisor));
    }
    let place = Math.pow(10, holder.length-1);
    for(let i = 0; i < holder.length; i++) {
        reversed += (holder[i] * place);
        place /= 10;
    }
    return reversed;
}
code of conduct - report abuse