Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(arr) {
- const mapWithTowns = new Map();
- arr.forEach((el) => {
- const [town, population] = el.split(/\s+<->\s+/);
- if (!mapWithTowns.has(town)) {
- mapWithTowns.set(town, 0);
- }
- mapWithTowns.set(town, mapWithTowns.get(town) + Number(population));
- });
- mapWithTowns.forEach((value, key) => {
- console.log(`${key} : ${value}`);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement