Finding smallest character after ' i - 1' and greater than temp [ i - 1 ]
let min = i ; let j , x = temp [ i - 1 ] ; for ( j = i + 1 ; j < temp . length ; j ++ ) if ( ( temp [ j ] < temp [ min ] ) && ( temp [ j ] > x ) ) min = j ;