Skip to main content
partial rollback to previous method
Source Link
Arnauld
  • 197.6k
  • 20
  • 179
  • 649

##JavaScript (ES6), 3737 bytes

f=(n,k=1)=>k>n?n--?f(n):'':f(n,k+1)+k

###Demo

f=(n,k=1)=>k>n?n--?f(n):'':f(n,k+1)+k

console.log(f(6))

###Alternate method for n < 10, 34 bytes (non-competing)

f=(n,s='1')=>--n?s+f(n,++s[0]+s):s

In JavaScript, strings are immutable. Therefore, it's impossible to alter the content of the Nth character of a string s by assigning a new value to s[N].

However, the expression ++s[N] is valid and does evaluate as one would expect, even if the string remains unchanged. For instance:

++"1"[0] // equals 2

And by extension:

s = "21"
++s[0] + s // equals "321"

###Demo

f=(n,s='1')=>--n?s+f(n,++s[0]+s):s

console.log(f(6))

##JavaScript (ES6), 37 34 bytes

f=(n,s='1')=>--n?s+f(n,++s[0]+s):s

In JavaScript, strings are immutable. Therefore, it's impossible to alter the content of the Nth character of a string s by assigning a new value to s[N].

However, the expression ++s[N] is valid and does evaluate as one would expect, even if the string remains unchanged. For instance:

++"1"[0] // equals 2

And by extension:

s = "21"
++s[0] + s // equals "321"

###Demo

f=(n,s='1')=>--n?s+f(n,++s[0]+s):s

console.log(f(6))

##JavaScript (ES6), 37 bytes

f=(n,k=1)=>k>n?n--?f(n):'':f(n,k+1)+k

###Demo

f=(n,k=1)=>k>n?n--?f(n):'':f(n,k+1)+k

console.log(f(6))

###Alternate method for n < 10, 34 bytes (non-competing)

f=(n,s='1')=>--n?s+f(n,++s[0]+s):s

In JavaScript, strings are immutable. Therefore, it's impossible to alter the content of the Nth character of a string s by assigning a new value to s[N].

However, the expression ++s[N] is valid and does evaluate as one would expect, even if the string remains unchanged. For instance:

++"1"[0] // equals 2

And by extension:

s = "21"
++s[0] + s // equals "321"
minor update
Source Link
Arnauld
  • 197.6k
  • 20
  • 179
  • 649

##JavaScript (ES6), 37 34 bytes

f=(n,s='1')=>--n?s+f(n,++s[0]+s):s

In JavaScript, strings are immutable. Therefore, it's impossible to alter the content of the Nth character of a string s by assigning a new value to s[N].

However, the expression ++s[N] is valid and does evaluate as one would expect, even if the string remains unchanged. For instance:

++"1"[0] // equals 2

And by extension:

s = "21"
++s[0] + s // equals "321"

###Demo

f=(n,s='1')=>--n?s+f(n,++s[0]+s):s

console.log(f(6))

##JavaScript (ES6), 37 34 bytes

f=(n,s='1')=>--n?s+f(n,++s[0]+s):s

In JavaScript, strings are immutable. Therefore, it's impossible to alter the content of the Nth character of a string s by assigning a new value to s[N].

However, the expression ++s[N] does evaluate as one would expect, even if the string remains unchanged. For instance:

++"1"[0] // equals 2

And by extension:

s = "21"
++s[0] + s // equals "321"

###Demo

f=(n,s='1')=>--n?s+f(n,++s[0]+s):s

console.log(f(6))

##JavaScript (ES6), 37 34 bytes

f=(n,s='1')=>--n?s+f(n,++s[0]+s):s

In JavaScript, strings are immutable. Therefore, it's impossible to alter the content of the Nth character of a string s by assigning a new value to s[N].

However, the expression ++s[N] is valid and does evaluate as one would expect, even if the string remains unchanged. For instance:

++"1"[0] // equals 2

And by extension:

s = "21"
++s[0] + s // equals "321"

###Demo

f=(n,s='1')=>--n?s+f(n,++s[0]+s):s

console.log(f(6))

minor update
Source Link
Arnauld
  • 197.6k
  • 20
  • 179
  • 649

##JavaScript (ES6), 37 34 bytes

f=(n,s='1')=>--n?s+f(n,++s[0]+s):s

In JavaScript, strings are immutable. Therefore, it's impossible to alter the content of the Nth character of a string s by assigning a new value to s[N].

However, the expression ++s[N] does evaluate as one would expect, even if the string remains unchanged.

  For instance:

++"1"[0] == 2
++"1"[0] // equals 2

And by extension:

++"21"[0]+"21" == "321"
s = "21"
++s[0] + s // equals "321"

###Demo

f=(n,s='1')=>--n?s+f(n,++s[0]+s):s

console.log(f(6))

##JavaScript (ES6), 37 34 bytes

f=(n,s='1')=>--n?s+f(n,++s[0]+s):s

In JavaScript, strings are immutable. Therefore, it's impossible to alter the content of the Nth character of a string s by assigning a new value to s[N].

However, the expression ++s[N] does evaluate as one would expect, even if the string remains unchanged.

  For instance:

++"1"[0] == 2

And by extension:

++"21"[0]+"21" == "321"

###Demo

f=(n,s='1')=>--n?s+f(n,++s[0]+s):s

console.log(f(6))

##JavaScript (ES6), 37 34 bytes

f=(n,s='1')=>--n?s+f(n,++s[0]+s):s

In JavaScript, strings are immutable. Therefore, it's impossible to alter the content of the Nth character of a string s by assigning a new value to s[N].

However, the expression ++s[N] does evaluate as one would expect, even if the string remains unchanged. For instance:

++"1"[0] // equals 2

And by extension:

s = "21"
++s[0] + s // equals "321"

###Demo

f=(n,s='1')=>--n?s+f(n,++s[0]+s):s

console.log(f(6))

added a note about ++s[0]
Source Link
Arnauld
  • 197.6k
  • 20
  • 179
  • 649
Loading
added a note about ++s[0]
Source Link
Arnauld
  • 197.6k
  • 20
  • 179
  • 649
Loading
saved 3 bytes
Source Link
Arnauld
  • 197.6k
  • 20
  • 179
  • 649
Loading
Source Link
Arnauld
  • 197.6k
  • 20
  • 179
  • 649
Loading