Rank of all elements in a Stream in descending order when they arrive | FindRank function to find rank ; Rank of first element is always 1 ; Iterate over array ; As element let say its rank is 1 ; Element is compared with previous elements ; If greater than previous than rank is incremented ; prvar rank ; array named arr ; length of arr
function FindRank ( arr , length ) { document . write ( " " + " " ) ; for ( i = 1 ; i < arr . length ; i ++ ) { var rank = 1 ; for ( j = 0 ; j < i ; j ++ ) { if ( arr [ j ] > arr [ i ] ) rank ++ ; } document . write ( rank + " " ) ; } } var arr = [ 88 , 14 , 69 , 30 , 29 , 89 ] ; var len = arr . length ; FindRank ( arr , len ) ;