Created
May 6, 2021 07:31
-
-
Save paulobunga/d7dbe246989842564fac417be3dbe678 to your computer and use it in GitHub Desktop.
Bus seat generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* AUTHOR: PAUL OBUNGA <[email protected] | |
* BUS SEAT GENERATOR | |
* TODO: Take care of odd seat numbers | |
* | |
*/ | |
let busOptions = { | |
license: "UBA 100L", | |
capacity: 72, | |
columns: 3, | |
status: "AVAILABLE", | |
tooltip: "Seat is available" | |
}; | |
let generate = ({ capacity, columns, ...busOptions }) => { | |
let sitData = []; | |
let rows = capacity / columns; | |
let sits = []; | |
for (let sit = 1; sit <= capacity; sit++) { | |
sits.push({ id: sit, ...busOptions }); | |
if (sits.length == capacity) { | |
console.log("Sit iteration complete"); | |
for (let cols = 1; cols <= columns; cols++) { | |
let data = sits.slice(rows * cols - rows, rows * cols); | |
sitData.push(data); | |
} | |
} | |
} | |
return sitData; | |
}; | |
seatsToGenerate = generate(busOptions); | |
console.log(seatsToGenerate); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment