Well, there are two major requirements of the task.
Inserting the - character at appropriate locations within the string
Converting the string to lowercase
I don’t think it is advisable to first convert the string to lowercase before replacing the word separator with -. From the test cases given AllThe-small Things must convert to all-the-small-things. If you first convert to lowercase, you will get such cases wrong.
The biggest question is how do you know where to insert the - character i.e. where does a word start/end? Then you replace some characters using - or insert - accordingly. If you can figure that out, the challenge is as good as solved.
I converted the string to lowercase at the end, but I am still confused about how to do this properly.
I know to insert the - when a word starts/ends. And where the word starts/ends can be indicated by a space or an uppercase letter. I just don’t know how to go about saying this in code