Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Commonmark migration
Source Link

#JavaScript (ES6), (削除) 58 (削除ここまで) 56 bytes

JavaScript (ES6), (削除) 58 (削除ここまで) 56 bytes

Saved 2 bytes thanks to @l4m2 / @Downgoat

Takes input in currying syntax (s)(c).

s=>c=>s.replace(u=/./g,x=>u=x==c?'':u?x:x.toUpperCase())

Try it online!

###Commented

Commented

s => c => // given s and c
 s.replace(u = /./g, x => // initialize u to a RegExp; replace each character x in s with,
 u = // and update u to:
 x == c ? // if x is the separator:
 '' // an empty string
 : // else:
 u ? // if u is not an empty string:
 x // x unchanged
 : // else:
 x.toUpperCase() // x capitalized
 ) // end of replace()

#JavaScript (ES6), (削除) 58 (削除ここまで) 56 bytes

Saved 2 bytes thanks to @l4m2 / @Downgoat

Takes input in currying syntax (s)(c).

s=>c=>s.replace(u=/./g,x=>u=x==c?'':u?x:x.toUpperCase())

Try it online!

###Commented

s => c => // given s and c
 s.replace(u = /./g, x => // initialize u to a RegExp; replace each character x in s with,
 u = // and update u to:
 x == c ? // if x is the separator:
 '' // an empty string
 : // else:
 u ? // if u is not an empty string:
 x // x unchanged
 : // else:
 x.toUpperCase() // x capitalized
 ) // end of replace()

JavaScript (ES6), (削除) 58 (削除ここまで) 56 bytes

Saved 2 bytes thanks to @l4m2 / @Downgoat

Takes input in currying syntax (s)(c).

s=>c=>s.replace(u=/./g,x=>u=x==c?'':u?x:x.toUpperCase())

Try it online!

Commented

s => c => // given s and c
 s.replace(u = /./g, x => // initialize u to a RegExp; replace each character x in s with,
 u = // and update u to:
 x == c ? // if x is the separator:
 '' // an empty string
 : // else:
 u ? // if u is not an empty string:
 x // x unchanged
 : // else:
 x.toUpperCase() // x capitalized
 ) // end of replace()
added the new test cases and saved 2 bytes
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

#JavaScript (ES6), 58(削除) 58 (削除ここまで) 56 bytes

Saved 2 bytes thanks to @l4m2 / @Downgoat

Takes input in currying syntax (s)(c).

s=>c=>s.replace(u=/./g,x=>u=x==c?'':u<1u?x:x.toUpperCase():x)

Try it online! Try it online!

###Commented

s => c => // given s and c
 s.replace(u = /./g, x => // initialize u to a RegExp; replace each character x in s with,
 u = // and update u to:
 x == c ? // if x is the separator:
 '' // an empty string
 : // else:
 u <? 1 ? // if u is not an empty string:
 x.toUpperCase() // x capitalized
 // : x unchanged
 : // else:
 // x else:
 x.toUpperCase() // x unchangedcapitalized
 ) // end of replace()

Given that:

  • r < 1 === false if r is a RegExp
  • c < 1 === false if c is a printable ASCII character other than space or 0
  • "" < 1 === true

#JavaScript (ES6), 58 bytes

Takes input in currying syntax (s)(c).

s=>c=>s.replace(u=/./g,x=>u=x==c?'':u<1?x.toUpperCase():x)

Try it online!

###Commented

s => c => // given s and c
 s.replace(u = /./g, x => // initialize u to a RegExp; replace each character x in s with,
 u = // and update u to:
 x == c ? // if x is the separator:
 '' // an empty string
 : // else:
 u < 1 ? // if u is an empty string:
 x.toUpperCase() // x capitalized
 : // else:
 x // x unchanged
 ) // end of replace()

Given that:

  • r < 1 === false if r is a RegExp
  • c < 1 === false if c is a printable ASCII character other than space or 0
  • "" < 1 === true

#JavaScript (ES6), (削除) 58 (削除ここまで) 56 bytes

Saved 2 bytes thanks to @l4m2 / @Downgoat

Takes input in currying syntax (s)(c).

s=>c=>s.replace(u=/./g,x=>u=x==c?'':u?x:x.toUpperCase())

Try it online!

###Commented

s => c => // given s and c
 s.replace(u = /./g, x => // initialize u to a RegExp; replace each character x in s with,
 u = // and update u to:
 x == c ? // if x is the separator:
 '' // an empty string
 : // else:
 u ? // if u is not an empty string:
 x // x unchanged
 : // else:
 x.toUpperCase() // x capitalized
 ) // end of replace()
Rollback to Revision 2
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

#JavaScript (ES6), 47 bytes

Using the updated rules: -11 bytes thanks to @Shaggy

Takes input as either (s) or (s,c), but ignores the 2nd parameter anyway.

s=>s.replace(/[^a-z]./gi,x=>x[1].toUpperCase())

Try it online!


#Original answer, 58 bytes

Meant to work with any separator (including letters), as per the original rules.

Takes input in currying syntax (s)(c).

s=>c=>s.replace(u=/./g,x=>u=x==c?'':u<1?x.toUpperCase():x)

Try it online!

###Commented

s => c => // given s and c
 s.replace(u = /./g, x => // initialize u to a RegExp; replace each character x in s with,
 u = // and update u to:
 x == c ? // if x is the separator:
 '' // an empty string
 : // else:
 u < 1 ? // if u is an empty string:
 x.toUpperCase() // x capitalized
 : // else:
 x // x unchanged
 ) // end of replace()

Given that:

  • r < 1 === false if r is a RegExp
  • c < 1 === false if c is a printable ASCII character other than space or 0
  • "" < 1 === true

#JavaScript (ES6), 47 bytes

Using the updated rules: -11 bytes thanks to @Shaggy

Takes input as either (s) or (s,c), but ignores the 2nd parameter anyway.

s=>s.replace(/[^a-z]./gi,x=>x[1].toUpperCase())

Try it online!


#Original answer, 58 bytes

Meant to work with any separator (including letters), as per the original rules.

Takes input in currying syntax (s)(c).

s=>c=>s.replace(u=/./g,x=>u=x==c?'':u<1?x.toUpperCase():x)

Try it online!

###Commented

s => c => // given s and c
 s.replace(u = /./g, x => // initialize u to a RegExp; replace each character x in s with,
 u = // and update u to:
 x == c ? // if x is the separator:
 '' // an empty string
 : // else:
 u < 1 ? // if u is an empty string:
 x.toUpperCase() // x capitalized
 : // else:
 x // x unchanged
 ) // end of replace()

Given that:

  • r < 1 === false if r is a RegExp
  • c < 1 === false if c is a printable ASCII character other than space or 0
  • "" < 1 === true

#JavaScript (ES6), 58 bytes

Takes input in currying syntax (s)(c).

s=>c=>s.replace(u=/./g,x=>u=x==c?'':u<1?x.toUpperCase():x)

Try it online!

###Commented

s => c => // given s and c
 s.replace(u = /./g, x => // initialize u to a RegExp; replace each character x in s with,
 u = // and update u to:
 x == c ? // if x is the separator:
 '' // an empty string
 : // else:
 u < 1 ? // if u is an empty string:
 x.toUpperCase() // x capitalized
 : // else:
 x // x unchanged
 ) // end of replace()

Given that:

  • r < 1 === false if r is a RegExp
  • c < 1 === false if c is a printable ASCII character other than space or 0
  • "" < 1 === true
saved 11 bytes
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading
added the commented version
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading

AltStyle によって変換されたページ (->オリジナル) /