SHARE
TWEET

01. Garage

a guest Feb 8th, 2019 105 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solveGarage(inputArr) {
  2.     let garagesMap = new Map()
  3.  
  4.     for (let row of inputArr) {
  5.         let rowArr = row.split(' - ')
  6.         let garage = rowArr[0]
  7.         let carKeyValues = rowArr[1]
  8.         let availableCars = []
  9.  
  10.         if (!garagesMap.has(garage)) {
  11.             availableCars.push(carKeyValues)
  12.             garagesMap.set(garage, availableCars)
  13.  
  14.         } else {
  15.             availableCars = garagesMap.get(garage)
  16.             availableCars.push(carKeyValues)
  17.             garagesMap.set(garage, availableCars)
  18.         }
  19.     }
  20.  
  21.     let sortedGarages = [...garagesMap.entries()]
  22.         .sort((a, b) => Number(a[0]) - Number(b[0]))
  23.  
  24.     let output = ''
  25.     for (let [currGarage, currCarKeyValue] of sortedGarages) {
  26.         output += `Garage № ${currGarage}\n`
  27.  
  28.         for (let currCarProperties of currCarKeyValue) {
  29.  
  30.             for (let everySymbol of currCarProperties) {
  31.                 currCarProperties = currCarProperties.replace(': ', ' - ')
  32.             }
  33.  
  34.             output += `--- ${currCarProperties}\n`
  35.         }
  36.     }
  37.     console.log(output);
  38. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top