Guest User

Untitled

a guest
Dec 14th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. function pattern7 (n) {
  2. let currentLine;
  3.  
  4. for (let i=1; i<=n; i++) {
  5. currentLine = '';
  6. for (let j=1; j<=2*n; j++) {
  7.  
  8. // Print upperleft pattern
  9. if (i+j <= n+1)
  10. currentLine += '*';
  11. else
  12. currentLine += ' ';
  13.  
  14. // Print upperright pattern
  15. if (i>j-n)
  16. currentLine += ' ';
  17. else
  18. currentLine += '*';
  19. }
  20. console.log(currentLine);
  21. }
  22.  
  23. // Print lower half
  24. for (let i=1; i<=n; i++) {
  25. currentLine = '';
  26. for (let j=1; j<=2*n; j++) {
  27.  
  28. // Print lower left pattern
  29. if (j>i)
  30. currentLine += ' ';
  31. else
  32. currentLine += '*';
  33.  
  34. // Print lower right pattern
  35. if (i+j < 2*n+1)
  36. currentLine += ' ';
  37. else
  38. currentLine += '*';
  39. }
  40. console.log(currentLine);
  41. }
  42. }
Add Comment
Please, Sign In to add comment