Advertisement
fbinnzhivko

Untitled

Sep 25th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function draw4Squares(input) {
  2.     let n = Number(input[0]);
  3.     let horizontal = 2 * n - 1;
  4.     let vertical = (n % 2 == 0) ? n - 1 : n;
  5.     let result = "";
  6.     if (n == 2) {
  7.         for ( i = 0; i < 3; i++)
  8.         {
  9.             console.log("+".repeat(3));
  10.         }
  11.     }
  12.     else {
  13.         for (let r = 1; r <= vertical; r++) {
  14.             for (let c = 1; c <= horizontal; c++) {
  15.                 if (r == 1 || r == Math.ceil(vertical / 2) || r == vertical) {
  16.                     result += (c == 1 || c == n || c == horizontal) ? '+' : '-';
  17.                 }
  18.                 else {
  19.                     result += (c == 1 || c == n || c == horizontal) ? '|' : ' ';
  20.                 }
  21.             }
  22.             result += '\n';
  23.         }
  24.     }
  25.     console.log(result);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement