You are viewing a single comment's thread. Return to all comments →
I'd just like to share mine because it avoid 2 loops, even though the efficiency is still O(n) on other solutions, which is good.
function migratoryBirds(arr) { const birdSightings = {}; const maxSighted = arr.reduce((acc, curr) => { birdSightings[curr] = birdSightings[curr] + 1 || 1; return (birdSightings[curr] > (birdSightings[acc] || 0)) ? curr : (birdSightings[curr] == (birdSightings[acc] || 0)) ? Math.min(curr, acc) : acc; }, 1); return maxSighted; }
Seems like cookies are disabled on this browser, please enable them to open this website
Migratory Birds
You are viewing a single comment's thread. Return to all comments →
I'd just like to share mine because it avoid 2 loops, even though the efficiency is still O(n) on other solutions, which is good.