Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let map = new Map();
- let neighborhoods = input.shift().split(', ');
- for(let neighborhood of neighborhoods) {
- map.set(neighborhood, []);
- }
- for(let i = 0; i < input.length; i++) {
- let current = input.shift().split(' - ');
- let neighborhood = current[0];
- let person = current[1];
- if(neighborhoods.includes(neighborhood)) {
- map.get(neighborhood).push(person);
- }
- }
- let sorted = Array.from(map).sort((a, b) => {b[0] - a[0]});
- let neighborhoodName = sorted[0];
- let persons = sorted[1];
- for(let neighborhoodName of sorted) {
- console.log(`${neighborhoodName}: ${persons.length}`);
- for(let j = 0; j < persons.length; j++) {
- console.log(`--${persons[j]}`);
- }
- }
- }
- solve(['Abbey Street, Herald Street, Bright Mews',
- 'Bright Mews - Garry',
- 'Bright Mews - Andrea',
- 'Invalid Street - Tommy',
- 'Abbey Street - Billy'])
Advertisement
Add Comment
Please, Sign In to add comment