Skip to content

Instantly share code, notes, and snippets.

@nathaniel-miller
Created September 12, 2017 02:57
Show Gist options
  • Save nathaniel-miller/2b2f175028d13a4c418a32ab23da0994 to your computer and use it in GitHub Desktop.
Save nathaniel-miller/2b2f175028d13a4c418a32ab23da0994 to your computer and use it in GitHub Desktop.
Lifion Caps Splitter
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