Created
October 5, 2018 12:24
-
-
Save ivanelianto/fa3e1f60acf245f864fd4e3e0b23e324 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Test Case Source : | |
* https://github.com/rgehan/hacktoberfest-2k18-katas/blob/master/src/toPascalCase.test.js | |
*/ | |
let re = /([ |_|-])+[\w]/g; | |
let strings = ["I am pascalCase", | |
"i am pascalCase", | |
"front-end-developer", | |
"Front-end-developer", | |
"lets_go_to_the_gym", | |
"Lets_go_to_the_gym", | |
"areWeThereYet"]; | |
strings = strings.map((s) => | |
{ | |
s = s.replace(/^\w/, s[0].toUpperCase()); | |
let matches = s.match(re); | |
if (matches !== null) | |
{ | |
matches = matches.map((m) => | |
{ | |
s = s.replace(m, m.replace(/[ -_]/, '').toUpperCase()); | |
}); | |
} | |
return s; | |
}); | |
console.log(strings); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment