Files
js-practice/src/array/highest-frequency-ip.js
2020-05-20 16:00:09 +08:00

20 lines
368 B
JavaScript

/**
* @param ipLines: ip address
* @return: return highestFrequency ip address
*/
export const highestFrequency = function (ipLines) {
const map = new Map()
let max = 0
let maxN = ipLines[0]
ipLines.forEach(n => {
const temp = (map.get(n) || 0) + 1
map.set(n, temp)
if (temp > max) {
maxN = n
max = temp
}
})
return maxN
}