Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. const num = 5;
  2. const full = num*2;
  3. const last = full-1;
  4.  
  5. let topHalf = "";
  6. let bottomHalf = "";
  7.  
  8. for (let i = 1, j = last; i < j; i += 2, j-=2) {
  9. let strinz = `${i}`.repeat(i);
  10. let speiz = ' '.repeat(Math.floor((num-i)/2));
  11. topHalf += speiz + strinz + speiz + '\n';
  12. bottomHalf = speiz + strinz + '\n' + bottomHalf + speiz;
  13. }
  14.  
  15. const isOdd = !!(num%2);
  16. const median = (isOdd) ? `${num}`.repeat(num) + '\n' : '';
  17.  
  18. console.log(topHalf + median + bottomHalf);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement