Find the indices of the minimum && the maximum value
var val1 = Number . MAX_VALUE , mini = - 1 , val2 = Number . MIN_VALUE , maxi = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( a [ i ] < val1 ) { mini = i ; val1 = a [ i ] ; } if ( a [ i ] > val2 ) { maxi = i ; val2 = a [ i ] ; } } flag = 1 ;