Find the appropriate divisor to extract the leading digit
let divisor = 1 ; while ( parseInt ( n / divisor , 10 ) >= 10 ) divisor *= 10 ; while ( n != 0 ) { let leading = parseInt ( n / divisor , 10 ) ; let trailing = n % 10 ;