Intermediate Algorithm Scripting - Spinal Tap Case

I need help with this regex please.
I dont understand how spaces are being put into the string with the first .replace(). To me it just says lower case alphabet then uppercase, but I cant see the space which is being inserted anywhere.

Your code so far

function spinalCase(str) {
  // Create a variable for the white space and underscores.
  var regex = /\s+|_+/g;

  // Replace low-upper case to low-space-uppercase
  str = str.replace(/([a-z])([A-Z])/g, "$1 $2");

  // Replace space and underscore with -
  return str.replace(regex, "-").toLowerCase();
}

// test here
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/112.0.0.0 Safari/537.36

Challenge: Intermediate Algorithm Scripting - Spinal Tap Case

Link to the challenge:

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