maymunskoa

PascalCase-Splitter (Text Processing)

Mar 12th, 2020
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(string){
  2. let destructed = [];
  3. let newWord = '';
  4. let capLetter = '';
  5. for (const letter of string) {
  6.     if(letter === letter.toUpperCase()){
  7.         if (newWord.length === 0){
  8.             capLetter = letter;
  9.             newWord+=capLetter;
  10.         } else{
  11.             destructed.push(newWord);
  12.             newWord = '';
  13.             capLetter = letter;
  14.             newWord += capLetter;
  15.  
  16.         }
  17.        
  18.     }else{
  19.         newWord+=letter;
  20.     }
  21. }
  22. destructed.push(newWord);
  23. console.log(destructed.join(', '));
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment