Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Stefanacef/6c47957aac751ecda020aeea329094a7 to your computer and use it in GitHub Desktop.
Save Stefanacef/6c47957aac751ecda020aeea329094a7 to your computer and use it in GitHub Desktop.
Solution for "Migratory Birds" in Hackerrank
const arr=[1, 2, 3, 4,5, 4, 3, 2, 1, 3, 4]
function migratoryBirds(arr) {
let objectArr=arr.reduce((obj, b)=> {
obj[b] = ++obj[b] || 1;
return obj;
}, {});
// console.log(objectArr)
const maxVal=Math.max(...Object.values(objectArr))
const num=Object.keys(objectArr).find(key => objectArr[key] === maxVal)
return num
}
console.log(migratoryBirds(arr))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment