Skip to content

Instantly share code, notes, and snippets.

@see-why
Created January 18, 2022 08:17
Show Gist options
  • Save see-why/8655f405d2b45287c10f7f5291b344b3 to your computer and use it in GitHub Desktop.
Save see-why/8655f405d2b45287c10f7f5291b344b3 to your computer and use it in GitHub Desktop.
HackerRank Migratory Bird Challenge
//https://www.hackerrank.com/challenges/migratory-birds/problem?isFullScreen=true
function migratoryBirds(arr) {
// Write your code here
let count = 0;
let value = 0;
for(let item=1; item<=5; item++){
let frequency = 0;
arr.forEach((val) => val == item && frequency++)
if (frequency > count || (frequency == count && item < value)){
count = frequency;
value = item;
}
}
return value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment