Last active
May 26, 2023 12:12
-
-
Save Stefanacef/6c47957aac751ecda020aeea329094a7 to your computer and use it in GitHub Desktop.
Solution for "Migratory Birds" in Hackerrank
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
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