SHARE
TWEET

Untitled

a guest Apr 25th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const getStringSpace = (n) => {
  2.     let a = '';
  3.     for (let i = 0; i < n; i++) {
  4.         a = a + ' ';
  5.     }
  6.     a = a + 'x';
  7.     return a;
  8. }
  9.  
  10. const getLastLine = (n) => {
  11.     let a = '';
  12.     for (let i = 0; i < n; i++) {
  13.         a = a + 'x ';
  14.     }
  15.     return a;
  16. }
  17.  
  18. const main = () => {
  19.     const n = 5;
  20.     for (let i = 1; i <= n; i++) {
  21.         if (i === 1) {
  22.             console.log(getStringSpace(n - i));
  23.         } else if (i === n) {
  24.             console.log(getLastLine(n));
  25.         } else {
  26.             console.log(
  27.                 getStringSpace(n - i)
  28.                 + getStringSpace((i - 1) * 2 - 1)
  29.             );
  30.         }
  31.     }
  32. }
  33.  
  34. main();
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top