Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function garage(garagesInfoInput) {
- let garagesInfo = garagesInfoInput.slice();
- let garagesMap = new Map();
- while (garagesInfo.length != 0) {
- let [garage, carKeyValues] = garagesInfo.shift().split(' - ');
- if (!garagesMap.has(garage)) {
- garagesMap.set(garage, [carKeyValues]);
- } else {
- let availableCars = garagesMap.get(garage);
- availableCars.push(carKeyValues);
- garagesMap.set(garage, availableCars);
- };
- }
- let output = '';
- for (let [currGarage, currCarKeyValue] of [...garagesMap]) {
- output += `Garage № ${currGarage}\n`;
- for (let currCarProperties of currCarKeyValue) {
- currCarProperties = currCarProperties.replace(/: /g, ' - ');
- output += `--- ${currCarProperties}\n`;
- }
- }
- console.log(output);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement