Find repeated character present first in a string | Javascript program to find the first character that is repeated ; This is O ( N ^ 2 ) method ; Driver code
function findRepeatFirstN2 ( s ) { let p = - 1 , i , j ; for ( i = 0 ; i < s . length ; i ++ ) { for ( j = i + 1 ; j < s . length ; j ++ ) { if ( s [ i ] == s [ j ] ) { p = i ; break ; } } if ( p != - 1 ) break ; } return p ; } let str = " " ; let pos = findRepeatFirstN2 ( str ) ; if ( pos == - 1 ) document . write ( " " ) ; else document . write ( str [ pos ] ) ;