4 added 252 characters in body
source | link

Javascript

EDIT : Since there is a suggestion to not use % operator, I use a little trick now.

I know this is not a code-golf, but there is no reason to make it longer.

function r(n){v=0;while(n)v=n+10*(v-(n=~~(n/10)));return v}

r(13457) returns 75431

Moreover, it's a lot faster than string method (n.toString().split('').reverse().join('')) :

enter image description here

==> JSPerf report <==

Javascript

EDIT : Since there is a suggestion to not use % operator, I use a little trick now.

I know this is not a code-golf, but there is no reason to make it longer.

function r(n){v=0;while(n)v=n+10*(v-(n=~~(n/10)));return v}

r(13457) returns 75431

Javascript

EDIT : Since there is a suggestion to not use % operator, I use a little trick now.

I know this is not a code-golf, but there is no reason to make it longer.

function r(n){v=0;while(n)v=n+10*(v-(n=~~(n/10)));return v}

r(13457) returns 75431

Moreover, it's a lot faster than string method (n.toString().split('').reverse().join('')) :

enter image description here

==> JSPerf report <==

3 deleted 5 characters in body
source | link

Javascript

EDIT : Since there is a suggestion to not use % operator, I use a little trick now.

I know this is not a code-golf, but there is no reason to make it longer.

function r(n){v=0;while(n){w=n;n=~~v=n+10*(v-(n=~~(n/10);v=10*(v-n)+w}return);return v}

r(13457) returns 75431

Javascript

EDIT : Since there is a suggestion to not use % operator, I use a little trick now.

I know this is not a code-golf, but there is no reason to make it longer.

function r(n){v=0;while(n){w=n;n=~~(n/10);v=10*(v-n)+w}return v}

r(13457) returns 75431

Javascript

EDIT : Since there is a suggestion to not use % operator, I use a little trick now.

I know this is not a code-golf, but there is no reason to make it longer.

function r(n){v=0;while(n)v=n+10*(v-(n=~~(n/10)));return v}

r(13457) returns 75431

2 added 92 characters in body
source | link

Javascript

EDIT : Since there is a suggestion to not use % operator, I use a little trick now.

I know this is not a code-golf, but there is no reason to make it longer.

function r(n){v=0;while(n){v=v*10+n%10;n=Math.floorw=n;n=~~(n/10);v=10*(v-n)+w}return v}

r(13457) returns 75431

Javascript

I know this is not a code-golf, but there is no reason to make it longer.

function r(n){v=0;while(n){v=v*10+n%10;n=Math.floor(n/10)}return v}

r(13457) returns 75431

Javascript

EDIT : Since there is a suggestion to not use % operator, I use a little trick now.

I know this is not a code-golf, but there is no reason to make it longer.

function r(n){v=0;while(n){w=n;n=~~(n/10);v=10*(v-n)+w}return v}

r(13457) returns 75431

1
source | link