Mode of frequencies of given array elements | Function to find the mode of the frequency of the array ; Stores the frequencies of array elements ; Traverse through array elements and count frequencies ; Stores the frequencies 's of  frequencies of array elements ; Stores the minimum value ; Find the Mode in 2 nd map ; Search for this Mode ; When mode is find then return to main function . ; If mode is not found ; Driver Code
function countFreq ( arr , n ) { let mp1 = new Map ( ) ; for ( let i = 0 ; i < n ; ++ i ) { if ( mp1 . has ( arr [ i ] ) ) { mp1 . set ( arr [ i ] , mp1 . get ( arr [ i ] ) + 1 ) ; } else { mp1 . set ( arr [ i ] , 1 ) ; } } let mp2 = new Map ( ) ; for ( let [ key , value ] of mp1 . entries ( ) ) { if ( mp2 . has ( value ) ) { mp2 . set ( value , mp2 . get ( value ) + 1 ) ; } else { mp2 . set ( value , 1 ) ; } } let M = Number . MIN_VALUE ; for ( let [ key , value ] of mp2 . entries ( ) ) { M = Math . max ( M , value ) ; } for ( let [ key , value ] of mp2 . entries ( ) ) { if ( M == value ) { return key ; } } return 0 ; } let arr = [ 6 , 10 , 3 , 10 , 8 , 3 , 6 , 4 ] ; let n = arr . length ; document . write ( countFreq ( arr , n ) ) ;