sets all repeating characters to - 2 and non - repeating characters contain the index where they occur
for ( var i = 0 ; i < str . length ; i ++ ) { if ( fi [ str . charCodeAt ( i ) ] == - 1 ) { fi [ str . charCodeAt ( i ) ] = i ; } else { fi [ str . charCodeAt ( i ) ] = - 2 ; } } var res = Infinity ; for ( var i = 0 ; i < 256 ; i ++ ) {