Created
July 30, 2018 16:19
-
-
Save celsopalmeiraneto/ba5e10f3ae18f11c2f18db8cd32df568 to your computer and use it in GitHub Desktop.
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 convertCamelCaseToSnakeCase(text) { | |
const inputLines = text.split('\n'); | |
const outputLines = inputLines.map((line) => { | |
return Array.from(line).reduce((acc, v, i) => { | |
if (i == 0) { | |
acc += v.toLocaleLowerCase(); | |
return acc; | |
} | |
if (v.toLocaleUpperCase() == v) { | |
acc += '_'; | |
} | |
acc += v.toLocaleLowerCase(); | |
return acc; | |
}, ''); | |
}); | |
return outputLines.join('\n'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment