Guest User

Untitled

a guest
Dec 12th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. function pattern4 (num) {
  2. let currentLine = '';
  3.  
  4. for (let i=1; i<=num; i++) {
  5. currentLine = '';
  6.  
  7. // Print left white spaces
  8. for (let j=num; j>i; j--) {
  9. currentLine += " ";
  10. }
  11.  
  12. // Print numbers
  13. for (let j=i; j<=(2*i-1); j++) {
  14. currentLine += j + " ";
  15. }
  16. for (let j=(2*i-1)-1; j>=i; j--) {
  17. currentLine += j + " ";
  18. }
  19.  
  20. // Print the line
  21. console.log(currentLine);
  22. }
  23. }
Add Comment
Please, Sign In to add comment