Created
September 12, 2017 02:57
-
-
Save nathaniel-miller/2b2f175028d13a4c418a32ab23da0994 to your computer and use it in GitHub Desktop.
Lifion Caps Splitter
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 capsSplitter(string) { | |
let words = []; | |
let word = string[0]; | |
for(let i = 1; i < string.length; i++) { | |
let currentChar = string[i]; | |
let CapitalChar = string[i].toUpperCase(); | |
if(currentChar == CapitalChar) { | |
words.push(word); | |
word = currentChar; | |
} else { | |
word = word.concat(currentChar); | |
} | |
} | |
words.push(word); | |
return words; | |
} | |
function newLineJoiner(words) { | |
let line = words[0]; | |
for(let i = 1; i < words.length; i++) { | |
line = line.concat('\n', words[i]); | |
} | |
return line; | |
} | |
let input = 'splitThisSentenceIntoNewLineS'; | |
let words = capsSplitter(input); | |
console.log(newLineJoiner(words)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment