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