Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Building */
- function building(input) {
- let floors = Number(input.shift());
- let rooms = Number(input.shift());
- let lApartments = ''; /* Variable for L Apartments */
- let oOffices = ''; /* Variable for O Offices */
- let aApartments = ''; /* Variable for A Apartments */
- for (let i = floors; i >= 1; i--) {
- for (let r = 0; r < rooms; r++) {
- if (i % 2 === 0) { /* offices O */
- if (i === floors || floors === 1) { /* Checking if i = the last floor OR if we have only one floor */
- lApartments += `L${i}${r} `; /* Concatenating */
- if (r === rooms - 1) { /* If r is equal to (rooms - 1), then we print the results on the console and continue with the loop */
- console.log(lApartments);
- }
- } else {
- oOffices += `O${i}${r} `; /* Concatenating */
- if (r === rooms - 1) {
- console.log(oOffices);
- }
- }
- } else { /* apartments A */
- if (i === floors || floors === 1) {
- lApartments += `L${i}${r} `; /* Concatenating */
- if (r === rooms - 1) {
- console.log(lApartments);
- }
- } else {
- aApartments += `A${i}${r} `; /* Concatenating */
- if (r === rooms - 1) {
- console.log(aApartments);
- }
- }
- }
- }
- /* Refreshing the Values of the Both Variables
- Because We Want Them on New Lines Every for Every
- New Floor */
- oOffices = '';
- aApartments = '';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement