Number of times Maximum and minimum value updated during traversal of array | Function to find the number of times minimum and maximum value updated during the traversal of the given array ; Increment i if new highest value occurs Increment j if new lowest value occurs ; Driver Code
function maxUpdated ( arr ) { let h_score = arr [ 0 ] ; let l_score = arr [ 0 ] ; let i = 1 , j = 1 ; for ( let n in arr ) { if ( h_score < arr [ n ] ) { h_score = n ; i ++ ; } if ( l_score > n ) { l_score = n ; j ++ ; } } document . write ( " " ) ; document . write ( " " + i + " " ) ; document . write ( " " ) ; document . write ( " " + j ) ; } let arr = [ 10 , 5 , 20 , 22 ] ; maxUpdated ( arr ) ;