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; }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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).