Advertisement
SirJoni

spinalCase

Jun 29th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. console.log(str.match(/[A-Z][a-z]+/g));
  2.  
  3. function spinalCase(str) {
  4.   arr =  [" ", "-", "_"];
  5.   for (i = 0; i < str.length; i++) {
  6.     if (i !== 0 && str[i] === str[i].toUpperCase() && arr.indexOf(str[i - 1]) === - 1 && arr.indexOf(str[i]) === - 1) {
  7.       console.log(str[i], str[i - 1], str);
  8.     }
  9.   }
  10.   str = str.replace(/ /g, "-");
  11.   str = str.replace(/_/g, "-");
  12.   return str;
  13. }
  14.  
  15. spinalCase('thisIsSpinalTap');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement