#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())
###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())
###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())
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(削除) 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)
###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 === falseif r is a RegExpc < 1 === falseif c is a printable ASCII character other than space or0"" < 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)
###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 === falseif r is a RegExpc < 1 === falseif c is a printable ASCII character other than space or0"" < 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())
###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), 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())
#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)
###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 === falseif r is a RegExpc < 1 === falseif c is a printable ASCII character other than space or0"" < 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())
#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)
###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 === falseif r is a RegExpc < 1 === falseif c is a printable ASCII character other than space or0"" < 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)
###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 === falseif r is a RegExpc < 1 === falseif c is a printable ASCII character other than space or0"" < 1 === true