Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(string){
- let destructed = [];
- let newWord = '';
- let capLetter = '';
- for (const letter of string) {
- if(letter === letter.toUpperCase()){
- if (newWord.length === 0){
- capLetter = letter;
- newWord+=capLetter;
- } else{
- destructed.push(newWord);
- newWord = '';
- capLetter = letter;
- newWord += capLetter;
- }
- }else{
- newWord+=letter;
- }
- }
- destructed.push(newWord);
- console.log(destructed.join(', '));
- }
Advertisement
Add Comment
Please, Sign In to add comment