Skip to content

Instantly share code, notes, and snippets.

@alanbsmith
Created December 30, 2019 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanbsmith/fb4f58b9e5e3372153f6cdc6d66de15c to your computer and use it in GitHub Desktop.
Save alanbsmith/fb4f58b9e5e3372153f6cdc6d66de15c to your computer and use it in GitHub Desktop.
pascal-ifying strings and arrays in JS
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