Spinal Tap Case - Why doesn't my code work?

Hi all,

I’m confused as to why my code isn’t passing the exercise. When I run the code it seems to output exactly what it is supposed to, but I’m still getting an error. Please can someone shed a light on what is tripping me up here.

function spinalCase(str) {
  return str
  .replace(/[-_]/, " ")
  .split(/(\s|[A-Z][a-z]*)/g)
  .map(elem => elem.replace(" ", ""))
  .filter(Boolean)
  .join('-')
  .toLowerCase();
}

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

This is giving me this error:

Thanks

Hello~!

The actual string that gets called for this function is The_Andy_Griffith_Show (there is a known bug in the parser which we are working on fixing). Try console.log(spinalCase("The_Andy_Griffith_Show")) and see what gets returned :slightly_smiling_face:

Oh wow that’s a bit of an eye opener. That explains it haha.

… aaah I missed the g in my first regex! if I do .replace(/[-_]/g, " ") it passes!

Thank you! :smile:

1 Like