Skip to main content
Commonmark migration
Source Link

#JavaScript (ES6), 142 140 134 117 bytes n=>(g=x=>x?${t= [r=repeat](n-x--)}\\${s= [r](x)}|${s}/${t} +g(x):-r)(n)+O+[...g(n)].reverse().join``

JavaScript (ES6), 142 140 134 117 bytes

n=>(g=x=>x?`${t=` `[r=`repeat`](n-x--)}\\${s=` `[r](x)}|${s}/${t}
`+g(x):`-`[r](n))(n)+`O`+[...g(n)].reverse().join``

##Try It

Try It

f=
n=>(g=x=>x?`${t=` `[r=`repeat`](n-x--)}\\${s=` `[r](x)}|${s}/${t}
`+g(x):`-`[r](n))(n)+`O`+[...g(n)].reverse().join``
i.addEventListener("input",_=>o.innerText=f(+i.value))
o.innerText=f(i.value=1)
<input id=i type=number><pre id=o>

#JavaScript (ES6), 142 140 134 117 bytes n=>(g=x=>x?${t= [r=repeat](n-x--)}\\${s= [r](x)}|${s}/${t} +g(x):-r)(n)+O+[...g(n)].reverse().join``


##Try It

f=
n=>(g=x=>x?`${t=` `[r=`repeat`](n-x--)}\\${s=` `[r](x)}|${s}/${t}
`+g(x):`-`[r](n))(n)+`O`+[...g(n)].reverse().join``
i.addEventListener("input",_=>o.innerText=f(+i.value))
o.innerText=f(i.value=1)
<input id=i type=number><pre id=o>

JavaScript (ES6), 142 140 134 117 bytes

n=>(g=x=>x?`${t=` `[r=`repeat`](n-x--)}\\${s=` `[r](x)}|${s}/${t}
`+g(x):`-`[r](n))(n)+`O`+[...g(n)].reverse().join``

Try It

f=
n=>(g=x=>x?`${t=` `[r=`repeat`](n-x--)}\\${s=` `[r](x)}|${s}/${t}
`+g(x):`-`[r](n))(n)+`O`+[...g(n)].reverse().join``
i.addEventListener("input",_=>o.innerText=f(+i.value))
o.innerText=f(i.value=1)
<input id=i type=number><pre id=o>

deleted 2466 characters in body
Source Link
Shaggy
  • 43.5k
  • 4
  • 36
  • 94

#JavaScript (ES6), 142 140 134134 117 bytes n=>(v=[...Array(n)].map(_=>g=x=>x?${t=" "[r="repeat"]t= [r=repeat](n-x--)}\\${s=" "[r]s= [r](x)}|${s}/${t} ,x=n+g(x).join:+"-"[r](n))+`O`+[...v].reverse().joinr)(n)+O+[...g(n)].reverse().join``

f=
n=>(v=[...Array(n)].map(_=>`$g=x=>x?`${t="t=` "[r="repeat"]`[r=`repeat`](n-x--)}\\${s="s=` "[r]`[r](x)}|${s}/${t}
`,x=n`+g(x).join``+":`-"[r]`[r](n))(n)+`O`+[...v]g(n)].reverse().join``
i.addEventListener("input",_=>o.innerText=f(+i.value))
o.innerText=f(i.value=1)
<input id=i type=number><pre id=o>

##Explanation

n=>                         :Anonymous function taking the integer input as an argument
                             via parameter n
(v=                         :Assign a string of the upper & left "rays" to variable v by ...
[...Array(n)]               :Creating an array of length n, destructuring it, ...
.map(_=>`                   :And mapping over it to populate it,
                             using an anonymous function that takes no input.
${t=" "[r="repeat](n-x--)}  :A space repeated n-x times and assigned to variable t,
                             used to indent each line of the upper "rays".
                            :Alias the repeat method to variable for later reuse.
\\                          :An escaped backslash for the upper left "ray".
${s=" "[r](x)}              :A space repeated x=x-1 times and assigned to variable s,
                             used to space the upper "rays".
|                           :A pipe for the upper middle "ray".
${s}                        :Repeat variable s.
/                           :A forward slash for the upper right "ray".
${t}                        :Repeat variable t.
                            :(We need trailing spaces on the upper "rays" to
                              indent the lower "rays" later.)
\n                          :A new line (A literal new line is actually used).
`,x=n)                      :Initialise variable x with a value of n and
                             finish mapping the array.
.join``                     :Join the array to a string.
+"-"[r](n))                 :Build the left ray by repeating a dash n times
                             and append it to the v string.
+`O`                        :Append an uppercase O to the overall string,
                             representing the centre of the "sun".
+                           :Append the following:
[...v]                      :Destructure the v string (upper & left rays) to
                             an array of individual characters, ...
.reverse()                  :Revserse the order of the elements in the array and ...
.join``                     :Join the array to a string,
                             giving us the right and lower "rays"

#JavaScript (ES6), 142 140 134 bytes n=>(v=[...Array(n)].map(_=>${t=" "[r="repeat"](n-x--)}\\${s=" "[r](x)}|${s}/${t} ,x=n).join+"-"[r](n))+`O`+[...v].reverse().join

f=
n=>(v=[...Array(n)].map(_=>`${t=" "[r="repeat"](n-x--)}\\${s=" "[r](x)}|${s}/${t}
`,x=n).join``+"-"[r](n))+`O`+[...v].reverse().join``
i.addEventListener("input",_=>o.innerText=f(+i.value))
o.innerText=f(i.value=1)
<input id=i type=number><pre id=o>

##Explanation

n=>                         :Anonymous function taking the integer input as an argument
                             via parameter n
(v=                         :Assign a string of the upper & left "rays" to variable v by ...
[...Array(n)]               :Creating an array of length n, destructuring it, ...
.map(_=>`                   :And mapping over it to populate it,
                             using an anonymous function that takes no input.
${t=" "[r="repeat](n-x--)}  :A space repeated n-x times and assigned to variable t,
                             used to indent each line of the upper "rays".
                            :Alias the repeat method to variable for later reuse.
\\                          :An escaped backslash for the upper left "ray".
${s=" "[r](x)}              :A space repeated x=x-1 times and assigned to variable s,
                             used to space the upper "rays".
|                           :A pipe for the upper middle "ray".
${s}                        :Repeat variable s.
/                           :A forward slash for the upper right "ray".
${t}                        :Repeat variable t.
                            :(We need trailing spaces on the upper "rays" to
                              indent the lower "rays" later.)
\n                          :A new line (A literal new line is actually used).
`,x=n)                      :Initialise variable x with a value of n and
                             finish mapping the array.
.join``                     :Join the array to a string.
+"-"[r](n))                 :Build the left ray by repeating a dash n times
                             and append it to the v string.
+`O`                        :Append an uppercase O to the overall string,
                             representing the centre of the "sun".
+                           :Append the following:
[...v]                      :Destructure the v string (upper & left rays) to
                             an array of individual characters, ...
.reverse()                  :Revserse the order of the elements in the array and ...
.join``                     :Join the array to a string,
                             giving us the right and lower "rays"

#JavaScript (ES6), 142 140 134 117 bytes n=>(g=x=>x?${t= [r=repeat](n-x--)}\\${s= [r](x)}|${s}/${t} +g(x):-r)(n)+O+[...g(n)].reverse().join``

f=
n=>(g=x=>x?`${t=` `[r=`repeat`](n-x--)}\\${s=` `[r](x)}|${s}/${t}
`+g(x):`-`[r](n))(n)+`O`+[...g(n)].reverse().join``
i.addEventListener("input",_=>o.innerText=f(+i.value))
o.innerText=f(i.value=1)
<input id=i type=number><pre id=o>
added 2443 characters in body
Source Link
Shaggy
  • 43.5k
  • 4
  • 36
  • 94

##Explanation

n=>                         :Anonymous function taking the integer input as an argument
                             via parameter n
(v=                         :Assign a string of the upper & left "rays" to variable v by ...
[...Array(n)]               :Creating an array of length n, destructuring it, ...
.map(_=>`                   :And mapping over it to populate it,
                             using an anonymous function that takes no input.
${t=" "[r="repeat](n-x--)}  :A space repeated n-x times and assigned to variable t,
                             used to indent each line of the upper "rays".
                            :Alias the repeat method to variable for later reuse.
\\                          :An escaped backslash for the upper left "ray".
${s=" "[r](x)}              :A space repeated x=x-1 times and assigned to variable s,
                             used to space the upper "rays".
|                           :A pipe for the upper middle "ray".
${s}                        :Repeat variable s.
/                           :A forward slash for the upper right "ray".
${t}                        :Repeat variable t.
                            :(We need trailing spaces on the upper "rays" to
                              indent the lower "rays" later.)
\n                          :A new line (A literal new line is actually used).
`,x=n)                      :Initialise variable x with a value of n and
                             finish mapping the array.
.join``                     :Join the array to a string.
+"-"[r](n))                 :Build the left ray by repeating a dash n times
                             and append it to the v string.
+`O`                        :Append an uppercase O to the overall string,
                             representing the centre of the "sun".
+                           :Append the following:
[...v]                      :Destructure the v string (upper & left rays) to
                             an array of individual characters, ...
.reverse()                  :Revserse the order of the elements in the array and ...
.join``                     :Join the array to a string,
                             giving us the right and lower "rays"

##Explanation

n=>                         :Anonymous function taking the integer input as an argument
                             via parameter n
(v=                         :Assign a string of the upper & left "rays" to variable v by ...
[...Array(n)]               :Creating an array of length n, destructuring it, ...
.map(_=>`                   :And mapping over it to populate it,
                             using an anonymous function that takes no input.
${t=" "[r="repeat](n-x--)}  :A space repeated n-x times and assigned to variable t,
                             used to indent each line of the upper "rays".
                            :Alias the repeat method to variable for later reuse.
\\                          :An escaped backslash for the upper left "ray".
${s=" "[r](x)}              :A space repeated x=x-1 times and assigned to variable s,
                             used to space the upper "rays".
|                           :A pipe for the upper middle "ray".
${s}                        :Repeat variable s.
/                           :A forward slash for the upper right "ray".
${t}                        :Repeat variable t.
                            :(We need trailing spaces on the upper "rays" to
                              indent the lower "rays" later.)
\n                          :A new line (A literal new line is actually used).
`,x=n)                      :Initialise variable x with a value of n and
                             finish mapping the array.
.join``                     :Join the array to a string.
+"-"[r](n))                 :Build the left ray by repeating a dash n times
                             and append it to the v string.
+`O`                        :Append an uppercase O to the overall string,
                             representing the centre of the "sun".
+                           :Append the following:
[...v]                      :Destructure the v string (upper & left rays) to
                             an array of individual characters, ...
.reverse()                  :Revserse the order of the elements in the array and ...
.join``                     :Join the array to a string,
                             giving us the right and lower "rays"
deleted 62 characters in body
Source Link
Shaggy
  • 43.5k
  • 4
  • 36
  • 94
Loading
deleted 13 characters in body
Source Link
Shaggy
  • 43.5k
  • 4
  • 36
  • 94
Loading
Source Link
Shaggy
  • 43.5k
  • 4
  • 36
  • 94
Loading