Created
May 29, 2020 11:47
-
-
Save MinSomai/d82d3e2271e4c5060f42985f6159b3a0 to your computer and use it in GitHub Desktop.
Intermediate Algorithm Scripting: Spinal Tap Case
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function spinalCase(str) { | |
| let reg = /([A-Z]*[a-z]+)/g; | |
| let result = []; | |
| str.match(reg).forEach(item=>{ | |
| result.push(item.toLowerCase()); | |
| }) | |
| return result.join("-"); | |
| } | |
| console.log(spinalCase('AllThe-small Things')); | |
| console.log(spinalCase('thisIsSpinalTap')); | |
| console.log(spinalCase('Teletubbies say Eh-oh')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment