Created
December 1, 2016 13:59
-
-
Save loretoparisi/169bc377fbb5f106ae24c03e8440135f to your computer and use it in GitHub Desktop.
JavaScript ucWords and CamelCase plus spread operator Array Concat example
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
var toCamelCase = function(str) { | |
return str | |
.replace(/\s(.)/g, function($1) { return $1.toUpperCase(); }) | |
.replace(/\s/g, '') | |
.replace(/^(.)/, function($1) { return $1.toLowerCase(); }); | |
} | |
var ucWords = function(str) { | |
return str.toLowerCase().replace(/\b[a-z]/g, function(letter) { | |
return letter.toUpperCase(); | |
}) | |
} | |
var names=["joffrey joffer","Lone starr", "darth vader"]; | |
[... names.map(item => ucWords(item)), ...names.map(item => toCamelCase(item))] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It will output