Most frequent word in an array of strings | Function returns word with highest frequency ; Create Dictionary to store word and it 's frequency ; Iterate through array of words ; If word already exist in Dictionary then increase it 's count by 1 ; Otherwise add word to Dictionary ; Create set to iterate over Dictionary ; Check for word having highest frequency ; Return word having highest frequency ; Driver code ; Print word having highest frequency
function findWord ( arr ) { var hs = { } ; for ( var i = 0 ; i < arr . length ; i ++ ) { if ( hs . hasOwnProperty ( arr [ i ] ) ) { hs [ arr [ i ] ] = hs [ arr [ i ] ] + 1 ; } else { hs [ arr [ i ] ] = 1 ; } } var Key = " " ; var Value = 0 ; for ( const [ key , value ] of Object . entries ( hs ) ) { if ( value > Value ) { Value = value ; Key = key ; } } return Key ; } var arr = [ " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , ] ; var sol = findWord ( arr ) ; document . write ( sol ) ;