Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const num = 5;
- const full = num*2;
- const last = full-1;
- let topHalf = "";
- let bottomHalf = "";
- for (let i = 1, j = last; i < j; i += 2, j-=2) {
- let strinz = `${i}`.repeat(i);
- let speiz = ' '.repeat(Math.floor((num-i)/2));
- topHalf += speiz + strinz + speiz + '\n';
- bottomHalf = speiz + strinz + '\n' + bottomHalf + speiz;
- }
- const isOdd = !!(num%2);
- const median = (isOdd) ? `${num}`.repeat(num) + '\n' : '';
- console.log(topHalf + median + bottomHalf);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement