text: Count of indices in an array that satisfy the given condition | Function to return the count of indices that satisfy the given condition ; To store the result ; To store the current maximum Initialized to 0 since there are only positive elements in the array ; i is a valid index ; Update the maximum so far ; Increment the counter ; Driver code
code: function countIndices ( arr , n ) { var cnt = 0 ; var max = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( max < arr [ i ] ) { max = arr [ i ] ; cnt ++ ; } } return cnt ; } var arr = [ 1 , 2 , 3 , 4 ] ; var n = arr . length ; document . write ( countIndices ( arr , n ) ) ;