Guest User

Untitled

a guest
Feb 17th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. /* Spinal Case Function for FreeCodeCamp's Javascript Algorithms and Data Structures
  2. Convert a string to spinal case. Spinal case is all-lowercase-words-joined-by-dashes.
  3. */
  4.  
  5. function spinalCase(str) {
  6. let newArr = str.match(/[A-Za-z]{1}[a-z]*|\s[a-z]+/g); //Match all words
  7. return newArr.join("-").replace(/\s/g, '').toLowerCase(); //join matched words with '-', delete spaces and convert all to lower case
  8. }
  9.  
  10. spinalCase('This Is Spinal Tap'); //returns "this-is-a-spinal-tap"
Add Comment
Please, Sign In to add comment