add: 最高频率的IP

This commit is contained in:
2020-05-19 05:59:30 +08:00
parent 57045d7772
commit 34a76e22b9
3 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,19 @@
/**
* @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
}