Advertisement
GeorgiLukanov87

20. Pascal-Case Splitter

Feb 23rd, 2023
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     let result = '';
  3.     let output = [];
  4.     result += input[0]
  5.    
  6.     for (let char of input.slice(1)) {
  7.         is_true = (containsUppercase(char))
  8.         if (is_true) {
  9.             output.push(result)
  10.             result = char
  11.         } else {
  12.             result += char
  13.         }
  14.  
  15.     }
  16.  
  17.     function containsUppercase(str) {
  18.         return Boolean(str.match(/[A-Z]/));
  19.     }
  20.     output.push(result)
  21.     console.log(output.join(', '))
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement