Advertisement
CLooker

Untitled

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