Drawing a bordered square with least time complexity in JS





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







-2















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.






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();












share|improve this question




















  • 2





    I think this question would be more suitable posted on Code Review Stack Exchange

    – NewToJS
    Nov 23 '18 at 1:55






  • 1





    There is, and this is not the place to ask. Follow @NewToJS's advice. This is a request for help improving already working code.

    – Mike 'Pomax' Kamermans
    Nov 23 '18 at 1:57




















-2















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.






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();












share|improve this question




















  • 2





    I think this question would be more suitable posted on Code Review Stack Exchange

    – NewToJS
    Nov 23 '18 at 1:55






  • 1





    There is, and this is not the place to ask. Follow @NewToJS's advice. This is a request for help improving already working code.

    – Mike 'Pomax' Kamermans
    Nov 23 '18 at 1:57
















-2












-2








-2








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.






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();












share|improve this 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.






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();








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();





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();






javascript time-complexity






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 1:52









Ele

25.5k52251




25.5k52251










asked Nov 23 '18 at 1:49









CoreDoCoreDo

1,02841118




1,02841118








  • 2





    I think this question would be more suitable posted on Code Review Stack Exchange

    – NewToJS
    Nov 23 '18 at 1:55






  • 1





    There is, and this is not the place to ask. Follow @NewToJS's advice. This is a request for help improving already working code.

    – Mike 'Pomax' Kamermans
    Nov 23 '18 at 1:57
















  • 2





    I think this question would be more suitable posted on Code Review Stack Exchange

    – NewToJS
    Nov 23 '18 at 1:55






  • 1





    There is, and this is not the place to ask. Follow @NewToJS's advice. This is a request for help improving already working code.

    – Mike 'Pomax' Kamermans
    Nov 23 '18 at 1:57










2




2





I think this question would be more suitable posted on Code Review Stack Exchange

– NewToJS
Nov 23 '18 at 1:55





I think this question would be more suitable posted on Code Review Stack Exchange

– NewToJS
Nov 23 '18 at 1:55




1




1





There is, and this is not the place to ask. Follow @NewToJS's advice. This is a request for help improving already working code.

– Mike 'Pomax' Kamermans
Nov 23 '18 at 1:57







There is, and this is not the place to ask. Follow @NewToJS's advice. This is a request for help improving already working code.

– Mike 'Pomax' Kamermans
Nov 23 '18 at 1:57














3 Answers
3






active

oldest

votes


















2














This is an alternative which reduces Space and Time complexity.



Time complexity: O(n)






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();

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








share|improve this answer

































    0














    Can use recursion






    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);

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








    share|improve this answer































      0














      Slight alteration to @Ele's version that allows for both a size and a filler to be passed in.






      function DrawSquare(size, filler) { 
      const line = filler.repeat(size);
      const mid = filler+' '.repeat(size-2)+filler;
      let lines = [line];

      for (var i = 1; i < size - 1; i++) {
      lines.push(mid);
      }

      lines.push(line);

      console.log(lines.join('n'));
      }

      DrawSquare(8, '*');





      If I was going to redraw the same thing several times I would change it to look like this:






      const cache = {};

      function DrawSquare(size, filler) {
      if (!cache[size]) {
      const line = filler.repeat(size);
      const mid = filler+' '.repeat(size-2)+filler;
      let lines = [line];

      for (var i = 1; i < size - 1; i++) {
      lines.push(mid);
      }

      lines.push(line);

      cache[size] = lines.join('n');
      }

      console.log(cache[size]);
      }


      console.time('first');
      DrawSquare(12, '*');
      console.timeEnd('first');

      console.time('second');
      DrawSquare(12, '*');
      console.timeEnd('second');








      share|improve this answer
























        Your Answer






        StackExchange.ifUsing("editor", function () {
        StackExchange.using("externalEditor", function () {
        StackExchange.using("snippets", function () {
        StackExchange.snippets.init();
        });
        });
        }, "code-snippets");

        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "1"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439780%2fdrawing-a-bordered-square-with-least-time-complexity-in-js%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        2














        This is an alternative which reduces Space and Time complexity.



        Time complexity: O(n)






        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();

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








        share|improve this answer






























          2














          This is an alternative which reduces Space and Time complexity.



          Time complexity: O(n)






          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();

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








          share|improve this answer




























            2












            2








            2







            This is an alternative which reduces Space and Time complexity.



            Time complexity: O(n)






            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();

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








            share|improve this answer















            This is an alternative which reduces Space and Time complexity.



            Time complexity: O(n)






            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();

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








            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();

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





            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();

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






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 23 '18 at 15:59

























            answered Nov 23 '18 at 2:04









            EleEle

            25.5k52251




            25.5k52251

























                0














                Can use recursion






                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);

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








                share|improve this answer




























                  0














                  Can use recursion






                  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);

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








                  share|improve this answer


























                    0












                    0








                    0







                    Can use recursion






                    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);

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








                    share|improve this answer













                    Can use recursion






                    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);

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








                    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);

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





                    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);

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






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 23 '18 at 2:58









                    Miller Cy ChanMiller Cy Chan

                    423511




                    423511























                        0














                        Slight alteration to @Ele's version that allows for both a size and a filler to be passed in.






                        function DrawSquare(size, filler) { 
                        const line = filler.repeat(size);
                        const mid = filler+' '.repeat(size-2)+filler;
                        let lines = [line];

                        for (var i = 1; i < size - 1; i++) {
                        lines.push(mid);
                        }

                        lines.push(line);

                        console.log(lines.join('n'));
                        }

                        DrawSquare(8, '*');





                        If I was going to redraw the same thing several times I would change it to look like this:






                        const cache = {};

                        function DrawSquare(size, filler) {
                        if (!cache[size]) {
                        const line = filler.repeat(size);
                        const mid = filler+' '.repeat(size-2)+filler;
                        let lines = [line];

                        for (var i = 1; i < size - 1; i++) {
                        lines.push(mid);
                        }

                        lines.push(line);

                        cache[size] = lines.join('n');
                        }

                        console.log(cache[size]);
                        }


                        console.time('first');
                        DrawSquare(12, '*');
                        console.timeEnd('first');

                        console.time('second');
                        DrawSquare(12, '*');
                        console.timeEnd('second');








                        share|improve this answer




























                          0














                          Slight alteration to @Ele's version that allows for both a size and a filler to be passed in.






                          function DrawSquare(size, filler) { 
                          const line = filler.repeat(size);
                          const mid = filler+' '.repeat(size-2)+filler;
                          let lines = [line];

                          for (var i = 1; i < size - 1; i++) {
                          lines.push(mid);
                          }

                          lines.push(line);

                          console.log(lines.join('n'));
                          }

                          DrawSquare(8, '*');





                          If I was going to redraw the same thing several times I would change it to look like this:






                          const cache = {};

                          function DrawSquare(size, filler) {
                          if (!cache[size]) {
                          const line = filler.repeat(size);
                          const mid = filler+' '.repeat(size-2)+filler;
                          let lines = [line];

                          for (var i = 1; i < size - 1; i++) {
                          lines.push(mid);
                          }

                          lines.push(line);

                          cache[size] = lines.join('n');
                          }

                          console.log(cache[size]);
                          }


                          console.time('first');
                          DrawSquare(12, '*');
                          console.timeEnd('first');

                          console.time('second');
                          DrawSquare(12, '*');
                          console.timeEnd('second');








                          share|improve this answer


























                            0












                            0








                            0







                            Slight alteration to @Ele's version that allows for both a size and a filler to be passed in.






                            function DrawSquare(size, filler) { 
                            const line = filler.repeat(size);
                            const mid = filler+' '.repeat(size-2)+filler;
                            let lines = [line];

                            for (var i = 1; i < size - 1; i++) {
                            lines.push(mid);
                            }

                            lines.push(line);

                            console.log(lines.join('n'));
                            }

                            DrawSquare(8, '*');





                            If I was going to redraw the same thing several times I would change it to look like this:






                            const cache = {};

                            function DrawSquare(size, filler) {
                            if (!cache[size]) {
                            const line = filler.repeat(size);
                            const mid = filler+' '.repeat(size-2)+filler;
                            let lines = [line];

                            for (var i = 1; i < size - 1; i++) {
                            lines.push(mid);
                            }

                            lines.push(line);

                            cache[size] = lines.join('n');
                            }

                            console.log(cache[size]);
                            }


                            console.time('first');
                            DrawSquare(12, '*');
                            console.timeEnd('first');

                            console.time('second');
                            DrawSquare(12, '*');
                            console.timeEnd('second');








                            share|improve this answer













                            Slight alteration to @Ele's version that allows for both a size and a filler to be passed in.






                            function DrawSquare(size, filler) { 
                            const line = filler.repeat(size);
                            const mid = filler+' '.repeat(size-2)+filler;
                            let lines = [line];

                            for (var i = 1; i < size - 1; i++) {
                            lines.push(mid);
                            }

                            lines.push(line);

                            console.log(lines.join('n'));
                            }

                            DrawSquare(8, '*');





                            If I was going to redraw the same thing several times I would change it to look like this:






                            const cache = {};

                            function DrawSquare(size, filler) {
                            if (!cache[size]) {
                            const line = filler.repeat(size);
                            const mid = filler+' '.repeat(size-2)+filler;
                            let lines = [line];

                            for (var i = 1; i < size - 1; i++) {
                            lines.push(mid);
                            }

                            lines.push(line);

                            cache[size] = lines.join('n');
                            }

                            console.log(cache[size]);
                            }


                            console.time('first');
                            DrawSquare(12, '*');
                            console.timeEnd('first');

                            console.time('second');
                            DrawSquare(12, '*');
                            console.timeEnd('second');








                            function DrawSquare(size, filler) { 
                            const line = filler.repeat(size);
                            const mid = filler+' '.repeat(size-2)+filler;
                            let lines = [line];

                            for (var i = 1; i < size - 1; i++) {
                            lines.push(mid);
                            }

                            lines.push(line);

                            console.log(lines.join('n'));
                            }

                            DrawSquare(8, '*');





                            function DrawSquare(size, filler) { 
                            const line = filler.repeat(size);
                            const mid = filler+' '.repeat(size-2)+filler;
                            let lines = [line];

                            for (var i = 1; i < size - 1; i++) {
                            lines.push(mid);
                            }

                            lines.push(line);

                            console.log(lines.join('n'));
                            }

                            DrawSquare(8, '*');





                            const cache = {};

                            function DrawSquare(size, filler) {
                            if (!cache[size]) {
                            const line = filler.repeat(size);
                            const mid = filler+' '.repeat(size-2)+filler;
                            let lines = [line];

                            for (var i = 1; i < size - 1; i++) {
                            lines.push(mid);
                            }

                            lines.push(line);

                            cache[size] = lines.join('n');
                            }

                            console.log(cache[size]);
                            }


                            console.time('first');
                            DrawSquare(12, '*');
                            console.timeEnd('first');

                            console.time('second');
                            DrawSquare(12, '*');
                            console.timeEnd('second');





                            const cache = {};

                            function DrawSquare(size, filler) {
                            if (!cache[size]) {
                            const line = filler.repeat(size);
                            const mid = filler+' '.repeat(size-2)+filler;
                            let lines = [line];

                            for (var i = 1; i < size - 1; i++) {
                            lines.push(mid);
                            }

                            lines.push(line);

                            cache[size] = lines.join('n');
                            }

                            console.log(cache[size]);
                            }


                            console.time('first');
                            DrawSquare(12, '*');
                            console.timeEnd('first');

                            console.time('second');
                            DrawSquare(12, '*');
                            console.timeEnd('second');






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 23 '18 at 3:17









                            IntervaliaIntervalia

                            5,16511135




                            5,16511135






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439780%2fdrawing-a-bordered-square-with-least-time-complexity-in-js%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

                                ComboBox Display Member on multiple fields

                                Is it possible to collect Nectar points via Trainline?