Vassil_Iliev

RombusGG

Mar 11th, 2022
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function romboidHalfingTheRows(input) {
  2.  
  3.     // in case the pyramid is even numver rows, the diamond will be rows-1 rows, because, otherwise it can't get appropriate center point to turn into diamond.
  4.  
  5.     let rows = input[0];
  6.     let stars = '';
  7.     let spaces = '';
  8.     let secondSpaces = '';
  9.     let seconsStars = '';
  10.     let oddCasesString = '';
  11.  
  12.  
  13.     for (let i = 1; i <= rows; i++) { //Making the first half which is normal pyramid and it's rows are half of the all rolls
  14.         if (i <= rows / 2) { //defining when the normal pyramid needs to stop printing
  15.             if (i === 1) {
  16.                 stars += '*'
  17.             } else {
  18.                 stars += '**'
  19.             }
  20.  
  21.             for (let j = 1; j <= rows - i; j++) {
  22.                 spaces += ' '
  23.             }
  24.             console.log(spaces + stars)
  25.             spaces = '';
  26.         }
  27.     }
  28.  
  29.     if (rows % 2 !== 0) {  //Condition to make the pyrmid correct if there are odd numbers of rows
  30.         //if you don't do that step, and the rows are odd, the center two rows will be with equal stars
  31.         // and it wont form diamond shape
  32.         let counterSpaces = Math.trunc(rows * 0.5)
  33.  
  34.         let counterStars = rows;
  35.  
  36.         for (let m = 1; m <= counterSpaces; m++) {
  37.             oddCasesString += ' ';
  38.         }
  39.  
  40.         for (let l = 1; l <= counterStars; l++) {
  41.             oddCasesString += '*'
  42.         }
  43.         console.log(oddCasesString)
  44.     }
  45.  
  46.  
  47.     for (let i = 1; i <= rows - 1; i++) { // making the upsidedown pyramid and its rows are the other half of the all rows
  48.         if (i > rows / 2) {  //defining when to start printing it.
  49.             for (let j = rows - i; j >= 1; j--) {
  50.                 if (j === 1) {
  51.                     seconsStars += '*'
  52.                 } else {
  53.  
  54.                     seconsStars += '**'
  55.                 }
  56.             }
  57.  
  58.             for (let n = rows - i; n <= rows - 1; n++) {
  59.                 secondSpaces += ' '
  60.             }
  61.  
  62.             console.log(secondSpaces + seconsStars)
  63.             seconsStars = '';
  64.             secondSpaces = '';
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment