reverseInt

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
reverseInt manuel
function reverseInt(n) {
  let reverseInt = 0;
  while(n != 0) {
    reverseInt = (reverseInt * 10) + (n % 10);
    n = parseInt(n / 10)
  }

  return reverseInt;
}

reverseInt(2359)
reverseInt(-90)
reverseInt(0)
ready
reverseInt auto
function reverseInt(n = 0) {
  const reversed = n
    .toString()
    .split('')
    .reverse()
    .join('');

  return parseInt(reversed) * Math.sign(n);
}

reverseInt(2359)
reverseInt(-90)
reverseInt(0)
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.