Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solveGarage(inputArr) {
- let garagesMap = new Map()
- for (let row of inputArr) {
- let rowArr = row.split(' - ')
- let garage = rowArr[0]
- let carKeyValues = rowArr[1]
- let availableCars = []
- if (!garagesMap.has(garage)) {
- availableCars.push(carKeyValues)
- garagesMap.set(garage, availableCars)
- } else {
- availableCars = garagesMap.get(garage)
- availableCars.push(carKeyValues)
- garagesMap.set(garage, availableCars)
- }
- }
- let sortedGarages = [...garagesMap.entries()]
- .sort((a, b) => Number(a[0]) - Number(b[0]))
- let output = ''
- for (let [currGarage, currCarKeyValue] of sortedGarages) {
- output += `Garage № ${currGarage}\n`
- for (let currCarProperties of currCarKeyValue) {
- for (let everySymbol of currCarProperties) {
- currCarProperties = currCarProperties.replace(': ', ' - ')
- }
- output += `--- ${currCarProperties}\n`
- }
- }
- console.log(output);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement