Created
January 18, 2022 08:17
-
-
Save see-why/8655f405d2b45287c10f7f5291b344b3 to your computer and use it in GitHub Desktop.
HackerRank Migratory Bird Challenge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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