Solution to Spinal Tap Case in Intermediate Algorithm Scripting

Finally completed this challenge

It took me almost 2 hours to understand what’s going on and finally complete the challenge
After dropping several ideas of asking for help, finally finished this on my own.

:point_down:Here’s my solution for the challenge

function spinalCase(str) {

  let pat = /(^[A-Z]?[a-z]+)[\s,$]?|([A-Z]?[a-z]+)[\s,$]?/g

  let arr = str.match(pat)

  arr =>str.toLowerCase().trim())

  return arr.join("-")

spinalCase('Teletubbies say Eh-oh');

Please, check the solution, and figure out any pitfalls, if any…