Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- garage = (input) => {
- let garages = {};
- input.forEach(line => {
- let split = line.split(' - ');
- let num = split.shift();
- let car = {};
- split.shift().split(', ').map(part => part.split(': ')).forEach(el => {
- car[el[0]] = el[1];
- });
- if(garages[num] !== undefined) {
- garages[num].push(car);
- } else {
- garages[num] = [ car ];
- }
- });
- Object
- .entries(garages)
- .sort((a, b) => b[1].length - a[1].length)
- .forEach(([garage, cars]) => {
- console.log(`Garage № ${garage}`);
- cars.forEach(car => {
- let output = '';
- for(key in car) {
- output += `, ${key} - ${car[key]}`;
- }
- output = '---' + output.substr(1);
- console.log(output);
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment