Advertisement
CLooker

Untitled

Feb 2nd, 2018
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function migratoryBirds(n, ar) {
  2.   const bPopByType = ar.reduce(
  3.     (bPopByType, type) => (
  4.       Object.assign({}, bPopByType, ++bPopByType[type])
  5.     ), {1: 0, 2: 0, 3: 0, 4: 0, 5: 0});
  6.   const bPopTypes = Object.keys(bPopByType);
  7.   const most = bPopTypes.map(type => bPopByType[type]).reduce((result, pop) => pop > result ? result = pop : result, null);
  8.   return bPopTypes.filter(type => bPopByType[type] === most)[0];
  9. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement