Query involving regex and other potential options in Spinal Tap Case

Tell us what’s happening:

I’m still working on the final test case (AllThe-small Things), but I’m utterly perplexed by the second test case because when I console.log this test case I seem to pass. So what am I missing?

I have some ideas but I’m still figuring out how best to implement them a solution strategies:

  1. I need to cleanse the string of all potential punctuation so I can release it all with just dashes in between words
    2.I need to include another parameter in split besides the regex. For example, using a comma separation to include another parameter…(sounds the least useful but I wanted to mention it as something I’m considering)
    3.Use replace()

Am I onto the right trajectory with any of these?

Your code so far


function spinalCase(str) {
 var strNew = str.toLowerCase().split(/[^a-z$]/g).join('-');
 console.log(strNew);
  return strNew;
}

spinalCase('This Is Spinal Tap');

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/spinal-tap-case/

You may want to trim() the string first. I’ve noticed there are some spaces before or after to throw people. :wink:

Running through the different test cases and I’m stuck on the one involving underscores. What am I missing here? I feel like I’m making allowance for all potentialities within the tests I’ve been given?
Am I not understanding replace() correctly?
I can’t find any solution that doesn’t affect negatively the rest of the solved tests.


function spinalCase(str) {
var strNew = str.replace(/([A-Z])/g, ' $1').trim()
var strTwo = strNew.toLowerCase().split(" ").join('-').replace(/\--|\_/g, '-');
console.log(strTwo);
return strTwo;
}

spinalCase('This Is Spinal Tap')

Never mind. I figured it out.