Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(arr) {
- let companies = {};
- let arr2 = [];
- for (let el of arr) {
- let cur = el.split(' -> ');
- if (companies.hasOwnProperty(cur[0])) {
- companies[cur[0]].push(cur[1]);
- } else {
- companies[cur[0]] = [cur[1]];
- }
- }
- for (let key in companies) {
- arr2.push([key, companies[key]]);
- }
- // console.log(arr2);
- arr2.sort((a, b) => a[0].localeCompare(b[0]));
- for (let el of arr2) {
- el[1] = [...new Set(el[1])];
- console.log(el[0]);
- for (let el2 of el[1]) {
- console.log(`-- ${el2}`);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment