Skip to content

Instantly share code, notes, and snippets.

@codebubb
Created December 2, 2015 15:48
Show Gist options
  • Select an option

  • Save codebubb/f65ba85ce57a090b6d4d to your computer and use it in GitHub Desktop.

Select an option

Save codebubb/f65ba85ce57a090b6d4d to your computer and use it in GitHub Desktop.
// 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