N | Function that returns the N - th character ; initially null string ; starting integer ; add integers in string ; one digit numbers added ; more than 1 digit number , generate equivalent number in a string s1 and concatenate s1 into s . ; add the number in string ; reverse the string ; attach the number ; if the length exceeds N ; Driver Code
function NthCharacter ( n ) { let s = " " ; let c = 1 ; for ( let i = 1 ; ; i ++ ) { if ( c < 10 ) s += c . toString ( ) ; else { let s1 = " " ; let dup = c ; while ( dup > 0 ) { s1 += ( dup % 10 ) . toString ( ) ; dup = Math . floor ( dup / 10 ) ; } s1 = s1 . split ( " " ) . reverse ( ) . join ( " " ) ; s += s1 ; } c ++ ; if ( s . length >= n ) { return s [ n - 1 ] ; } } } let n = 11 ; document . write ( NthCharacter ( n ) ) ;