Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let garages = {};
- for (const line in input) {
- let [garage, carInfo] = input[line].split(' - ');
- if (!garages.hasOwnProperty(garage)) {
- garages[garage] = {};
- }
- garages[garage][line] = carInfo;
- }
- let entries = Object.entries(garages);
- for (const [garage, carObj] of entries) {
- console.log(`Garage № ${garage}`);
- for (const key in carObj) {
- while (carObj[key].includes(': ')) {
- carObj[key] = carObj[key].replace(': ', ' - ');
- }
- console.log(`--- ${carObj[key]}`);
- }
- }
- }
- solve(['1 - color: blue, fuel type: diesel',
- '1 - color: red, manufacture: Audi',
- '2 - fuel type: petrol',
- '4 - color: dark blue, fuel type: diesel, manufacture: Fiat'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement