Algorithm scripting..spinal tap case

please guys help me out. i have been trying to come out with the solution but my code only passes the first 3 tests… how do i improve on this code to pass all the tests.

let a = str.replace(/[^a-z0-9]+/gi,"");
  let b = a.split(/(?=[A-Z])/).join("-");
  let c = b.toLowerCase();
  
  return c;

Because you replace all non-alphanumeric character in the replace, you no longer can see the space characters which need to be converted to dashes.

Try moving the second line’s logic before the first line’s logic.

thanks man. I did as you said and was able to pass all the tests…