All files / leetCode 0007.ts

100% Statements 4/4
100% Branches 6/6
100% Functions 1/1
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16        5x           5x 1x   4x    
import { MAX_INT, MIN_INT } from './utils'
 
export default function reverse(x: number): number {
  const ret
    = x < 0
      ? Number.parseInt(
          `-${x.toString().slice(1).split('').reverse().join('')}`,
        )
      : Number.parseInt(x.toString().split('').reverse().join(''))
 
  if (ret > MAX_INT || ret < MIN_INT)
    return 0
 
  return ret
}