Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(args) {
- const neighborhood = {};
- args.shift()
- .split(', ')
- .forEach((name) => neighborhood[name] = []);
- args.forEach((element) => {
- const [district, name] = element.split(' - ');
- if (Object.prototype.hasOwnProperty.call(neighborhood, district)) {
- neighborhood[district].push(name);
- }
- });
- const districtSortedByCount = Object.entries(neighborhood).sort((a, b) => b[1].length - a[1].length);
- districtSortedByCount.forEach((element) => {
- const [district, inhabitants] = element;
- console.log(`${district}: ${inhabitants.length}`);
- inhabitants.forEach((person) => {
- console.log(`--${person}`);
- });
- });
- }
Add Comment
Please, Sign In to add comment