Spinal Tap Case

function spinalCase(str) {


return str.toLowerCase().split(/\W/).join("-");


}

console.log(spinalCase("thisIsSpinalTap"));

Struggling to get everything to pass for this problem. Right now only 2 out of 5 pass. Can someone help me without giving me the answer?

Well, there are two major requirements of the task.

  1. Inserting the - character at appropriate locations within the string
  2. Converting the string to lowercase

I don’t think it is advisable to first convert the string to lowercase before replacing the word separator with -. From the test cases given AllThe-small Things must convert to all-the-small-things. If you first convert to lowercase, you will get such cases wrong.

The biggest question is how do you know where to insert the - character i.e. where does a word start/end? Then you replace some characters using - or insert - accordingly. If you can figure that out, the challenge is as good as solved.

Thanks for the response!

return str.split(/\W/).join("-").toLowerCase();

I converted the string to lowercase at the end, but I am still confused about how to do this properly.

I know to insert the - when a word starts/ends. And where the word starts/ends can be indicated by a space or an uppercase letter. I just don’t know how to go about saying this in code

return str.split(/\s|_|(?=[A-Z])/).join("-").toLowerCase();

Nevermind, I figured it out

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.