Created
December 30, 2019 21:04
-
-
Save alanbsmith/fb4f58b9e5e3372153f6cdc6d66de15c to your computer and use it in GitHub Desktop.
pascal-ifying strings and arrays in JS
This file contains 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
function capitalize(str = '') { | |
let cap = str.substring(0,1).toUpperCase(); | |
let rest = str.substring(1).toLowerCase(); | |
return `${cap}${rest}` | |
} | |
function toPascalCase(str = '') { | |
let splitStr = str.split(' '); | |
return splitStr.map(word => capitalize(word)).join(''); | |
} | |
function pascalArr(arr = [], separator = '\n') { | |
return arr.map((str) => { | |
return toPascalCase(str) | |
}).join(separator) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment