Skip to main content
Fixed bug
Source Link
user81655
  • 11.2k
  • 1
  • 25
  • 50

JavaScript (ES6), 96101 characters

f=(n,i=0)=>i=>n?i-n?(b="║"[r="repeat"](i))+`╔${"═"[r]((n-i)*2-1)}╗${b}
`+f(n,i+1):(g="╨"[r](n))+"─"+g:""

Explanation

Recursive function that prints each line

f=(n,i=0)=>              // f = recursive function, i = current line (default = 0)
  n?                     // if n != 0
    i-n?                 // if we are not in the last line, print the line
      (b="║"[r="repeat"](i))+`╔${"═"[r]((n-i)*2-1)}╗${b}
`+f(n,i+1)               // add the output of the next line
    :(g="╨"[r](n))+"─"+g // if we ARE in the last line, print the last line
  :""                    // print nothing if n = 0

Test

Test does not use default parameter for browser compatibility.

var solution = f=(n,i)=>=>n?(i|=0)-n?(b="║"[r="repeat"](i))+`╔${"═"[r]((n-i)*2-1)}╗${b}
`+f(n,i+1):(g="╨"[r](n))+"─"+g:""
<input type="number" oninput="result.textContent=solution(this+this.value)" />
<pre id="result"></pre>

JavaScript (ES6), 96 characters

f=(n,i=0)=>i-n?(b="║"[r="repeat"](i))+`╔${"═"[r]((n-i)*2-1)}╗${b}
`+f(n,i+1):(g="╨"[r](n))+"─"+g

Explanation

Recursive function that prints each line

f=(n,i=0)=>            // f = recursive function, i = current line (default = 0)
  i-n?                 // if we are not in the last line, print the line
    (b="║"[r="repeat"](i))+`╔${"═"[r]((n-i)*2-1)}╗${b}
`+f(n,i+1)             // add the output of the next line
  :(g="╨"[r](n))+"─"+g // if we ARE in the last line, print the last line

Test

Test does not use default parameter for browser compatibility.

var solution = f=(n,i)=>(i|=0)-n?(b="║"[r="repeat"](i))+`╔${"═"[r]((n-i)*2-1)}╗${b}
`+f(n,i+1):(g="╨"[r](n))+"─"+g
<input type="number" oninput="result.textContent=solution(this.value)" />
<pre id="result"></pre>

JavaScript (ES6), 101 characters

f=(n,i=0)=>n?i-n?(b="║"[r="repeat"](i))+`╔${"═"[r]((n-i)*2-1)}╗${b}
`+f(n,i+1):(g="╨"[r](n))+"─"+g:""

Explanation

Recursive function that prints each line

f=(n,i=0)=>              // f = recursive function, i = current line (default = 0)
  n?                     // if n != 0
    i-n?                 // if we are not in the last line, print the line
      (b="║"[r="repeat"](i))+`╔${"═"[r]((n-i)*2-1)}╗${b}
`+f(n,i+1)               // add the output of the next line
    :(g="╨"[r](n))+"─"+g // if we ARE in the last line, print the last line
  :""                    // print nothing if n = 0

Test

Test does not use default parameter for browser compatibility.

var solution = f=(n,i)=>n?(i|=0)-n?(b="║"[r="repeat"](i))+`╔${"═"[r]((n-i)*2-1)}╗${b}
`+f(n,i+1):(g="╨"[r](n))+"─"+g:""
<input type="number" oninput="result.textContent=solution(+this.value)" />
<pre id="result"></pre>

Source Link
user81655
  • 11.2k
  • 1
  • 25
  • 50

JavaScript (ES6), 96 characters

f=(n,i=0)=>i-n?(b="║"[r="repeat"](i))+`╔${"═"[r]((n-i)*2-1)}╗${b}
`+f(n,i+1):(g="╨"[r](n))+"─"+g

Explanation

Recursive function that prints each line

f=(n,i=0)=>            // f = recursive function, i = current line (default = 0)
  i-n?                 // if we are not in the last line, print the line
    (b="║"[r="repeat"](i))+`╔${"═"[r]((n-i)*2-1)}╗${b}
`+f(n,i+1)             // add the output of the next line
  :(g="╨"[r](n))+"─"+g // if we ARE in the last line, print the last line

Test

Test does not use default parameter for browser compatibility.

var solution = f=(n,i)=>(i|=0)-n?(b="║"[r="repeat"](i))+`╔${"═"[r]((n-i)*2-1)}╗${b}
`+f(n,i+1):(g="╨"[r](n))+"─"+g
<input type="number" oninput="result.textContent=solution(this.value)" />
<pre id="result"></pre>