text: Frequency Measuring Techniques for Competitive Programming | Javascript program to count frequencies of array items having small values . ; Create an array to store counts . The size of array is limit + 1 and all values are initially 0 ; Traverse through array elements and count frequencies ( assuming that elements are limited by limit ) ; Driver code
code: function countFreq ( arr , n , limit ) { let count = new Array ( limit + 1 ) ; count . fill ( 0 ) ; for ( let i = 0 ; i < n ; i ++ ) count [ arr [ i ] ] ++ ; for ( let i = 0 ; i <= limit ; i ++ ) if ( count [ i ] > 0 ) document . write ( i + " " + count [ i ] + " " ) ; } let arr = [ 5 , 5 , 6 , 6 , 5 , 6 , 1 , 2 , 3 , 10 , 10 ] ; let n = arr . length ; let limit = 10 ; countFreq ( arr , n , limit ) ;