add: 最高频率的IP

This commit is contained in:
yige committed 2020-05-20 16:00:09 +08:00
1 parent 57045d7772
commit 34a76e22b9
3 files changed
+29

No files matched your search

+19
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
}