Created
December 2, 2015 15:48
-
-
Save codebubb/f65ba85ce57a090b6d4d to your computer and use it in GitHub Desktop.
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
| // Bonfire: Spinal Tap Case | |
| // Author: @codebubb | |
| // Challenge: http://www.freecodecamp.com/challenges/bonfire-spinal-tap-case | |
| // Learn to Code at Free Code Camp (www.freecodecamp.com) | |
| function spinalCase(str) { | |
| // "It's such a fine line between stupid, and clever." | |
| // --David St. Hubbins | |
| return str.replace(/([a-z][A-Z])|\s|_/g, function(match){ | |
| return match.length === 2 ? match[0] + "-" + match[1] : "-"; | |
| }).toLowerCase(); | |
| } | |
| spinalCase('This Is Spinal Tap'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment