Spinal Tap Case. Whose solution is shorter?

function spinalCase(str) {
return str.replace(/([^\s_])([A-Z])/g, “$1 $2”).toLowerCase().replace(/[\s_]/g, “-”);

Your solution is shorter (minus 3 symbols) :slight_smile:

function spinalCase(str) {
  return str.split(/[-\s_]|\B(?=[A-Z])/).join('-').toLowerCase();
}

The shortest solution! Great work!

Your solution is very specifc. If the string happened to have anything other than -, space and _ then this wouldn’t work.

It’s better to set it to [^A-Za-z0-9] and \B is unnecessary if you set the match to global(/g)