← Back to challenges

String Like Square

JavaScriptHardstringsformatting

Instructions

Create a function that takes a number and returns a string like square.

Examples

createSquare(-1) ➞ ""

createSquare(0) ➞ ""

createSquare(1) ➞ "#"

createSquare(2) ➞ "##\n##"

createSquare(3) ➞ "###\n# #\n###"

createSquare(4) ➞ "####\n#  #\n#  #\n####"

"####
#  #
#  #
####"

Notes

Square width <= 16383

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.