Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* Our main function has simplied a lot
*/
function changeCase(word, caseType) {
// We create a map of caseType -> function
const caseMap = {
"lower": convertToLower,
"camel": convertToCamel
}
// Look up the caseType "lower", "camel"
// The map will return its function, call it
caseType = caseType.trim().toLowerCase();
var conversionFunction = caseMap[caseType];
// Do we have this conversion function?
if ( conversionFunction != null )
return conversionFunction(word);
else
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment