daily pastebin goal
28%
SHARE
TWEET

Untitled

a guest Feb 17th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top