Advertisement
Guest User

figure-of-four-squares

a guest
Nov 27th, 2016
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. function figure4Squares(input) {
  2. let n = Number(input);
  3. if (n == 2) {
  4. console.log('+++');
  5. }
  6. else {
  7. console.log('+' + Array(n - 1).join('-') + '+' + Array(n - 1).join('-') + '+');
  8. for (let i = 1; i <= Math.floor((n - 3) / 2); i++) {
  9. console.log('|' + Array(n - 1).join(' ') + '|' + Array(n - 1).join(' ') + '|');
  10. }
  11. console.log('+' + Array(n - 1).join('-') + '+' + Array(n - 1).join('-') + '+');
  12. for (let i = 1; i <= Math.floor((n - 3) / 2); i++) {
  13. console.log('|' + Array(n - 1).join(' ') + '|' + Array(n - 1).join(' ') + '|');
  14. }
  15. console.log('+' + Array(n - 1).join('-') + '+' + Array(n - 1).join('-') + '+');
  16. }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement