Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. function drawSquare(width, height) {
  2. const matrix = [];
  3. let strMat = '\n';
  4.  
  5. for(let i = 0; i < width; i++) {
  6. matrix.push([]);
  7. for(let j = 0; j < height; j++) {
  8. if(i == 0 || i == height - 1 || j == 0 || j == width - 1) {
  9. matrix[i][j] = '#'
  10. } else {
  11. matrix[i][j] = ' '
  12. }
  13. strMat += ' ' + matrix[i][j] + ' ';
  14. }
  15. strMat += '\n';
  16. }
  17. console.log(strMat);
  18. }
  19.  
  20. function drawTriangle(width, height) {
  21. const matrix = [];
  22. let strMat = '\n';
  23.  
  24. for(let i = 0; i < width; i++) {
  25. matrix.push([]);
  26. for(let j = 0; j < height; j++) {
  27. if(i == height - 1 || j == 0 || i == j) {
  28. matrix[i][j] = '#'
  29. } else {
  30. matrix[i][j] = ' '
  31. }
  32. strMat += ' ' + matrix[i][j] + ' ';
  33. }
  34. strMat += '\n';
  35. }
  36. console.log(strMat);
  37. }
  38.  
  39. drawSquare(10, 10);
  40. drawTriangle(10, 10);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement