Skip to content

Instantly share code, notes, and snippets.

@ivanelianto
Created October 5, 2018 12:24
Show Gist options
  • Save ivanelianto/fa3e1f60acf245f864fd4e3e0b23e324 to your computer and use it in GitHub Desktop.
Save ivanelianto/fa3e1f60acf245f864fd4e3e0b23e324 to your computer and use it in GitHub Desktop.
/*
* 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