📅  最后修改于: 2022-03-11 15:01:31.446000             🧑  作者: Mango
// migratory birds hackerrank solution javascript
function migratoryBirds(arr) {
let map = {}, maxCount = 0, output = [];
for (let i = 0; i < arr.length; i++) {
if (!map[arr[i]]) {
map[arr[i]] = 1;
} else {
map[arr[i]] += 1;
}
if (map[arr[i]] > maxCount) {
maxCount = map[arr[i]];
}
}
for (let j = 0; j < arr.length; j++) {
if (map[arr[j]] === maxCount) {
output.push(arr[j]);
}
}
return Math.min(...output);
}