We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
functionmigratoryBirds(arr){// Write your code hereletresObj={};lethightest;letkey;arr.forEach((element)=>{if(resObj[element]){resObj[element]=resObj[element]+1;if(hightest&&key){if(resObj[element]>hightest){hightest=resObj[element];key=element;}elseif(resObj[element]==hightest){if(element<key){key=element;}}}else{hightest=resObj[element];key=element;}}else{resObj[element]=1;}});returnkey;}
Cookie support is required to access HackerRank
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 →
java script solution within one loop