Skip to content

Instantly share code, notes, and snippets.

Created December 3, 2015 02:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/0fd99706fc29942c856e to your computer and use it in GitHub Desktop.
Save anonymous/0fd99706fc29942c856e to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/nirajkrz 's solution for Bonfire: Spinal Tap Case
// Bonfire: Spinal Tap Case
// Author: @nirajkrz
// Challenge: http://www.freecodecamp.com/challenges/bonfire-spinal-tap-case
// Learn to Code at Free Code Camp (www.freecodecamp.com)
//Convert a string to spinal case. Spinal case is all-lowercase-words-joined-by-dashes.
function spinalCase(str) {
// "It's such a fine line between stupid, and clever."
// --David St. Hubbins
// Create a variable for the white space and underscores.
var regex = /\s+|_+/g;
// Replace low-upper case to low-space-uppercase
str = str.replace(/([a-z])([A-Z])/g, '$1 $2');
// Replace space and underscore with -
return str.replace(regex, '-').toLowerCase();
}
spinalCase('This Is Spinal Tap');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment