Question: I just wrote a code that draws a bordered square. 

Given the square size of 5 for example, the code should print the following multi-line string:

```
#####
#   #
#   #
#   #
#####

```

and I was wondering if there's anyway of simplifying this more and reduce time complexity. 

```js
var BoxFiller = "#";
var BoxSize = 8;
var Row = "";

function DrawSquare() {

  for (i = 0; i < BoxSize; i++) {
    var r = BoxSize - 1;

    if (i == 0 || i == r) {
      Row = BoxFiller.repeat(BoxSize);
    } else {
      Row = BoxFiller + " ".repeat(BoxSize - 2) + BoxFiller;
    }

    console.log(Row);

  }
}

DrawSquare();
```

Answer: 
This is an alternative which reduces Space and Time complexity.

*Time complexity: `O(n)`*

```js
var BoxFiller = "#";
var BoxSize = 8;
var Row = "";
var spaces = " ".repeat(BoxSize - 2);
var hashtags = BoxFiller.repeat(BoxSize);

function DrawSquare() {  
  console.log(hashtags);

  for (var i = 1; i < BoxSize - 1; i++) {
    console.log(BoxFiller + spaces + BoxFiller);
  }

  console.log(hashtags);
}

DrawSquare();
```

```css
.as-console-wrapper { max-height: 100% !important; top: 0; }
```
Can use recursion

```js
let BoxFiller = "#";
let Row = "";
var spaces, hashtags;

function DrawRow(BoxSize, CurrPos) { 
 if(CurrPos >= BoxSize - 2)
  return;

 console.log(BoxFiller + spaces + BoxFiller);
 DrawRow(BoxSize, CurrPos + 1);
}

function DrawSquare(BoxSize) { 
 spaces = " ".repeat(BoxSize - 2);
 hashtags = BoxFiller.repeat(BoxSize);
 console.log(hashtags);
 DrawRow(BoxSize, 0);
 console.log(hashtags);
}

DrawSquare(8);
```

```css
.as-console-wrapper { max-height: 100% !important; top: 0; }
```