Then find the first and last index of given character in the given string
for ( var i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] == c ) { for ( var j = s . length - 1 ; j > i ; j -- ) if ( s [ j ] == c ) { if ( j == i ) break ;