Tell us what’s happening:
Why can’t the third line replace the code in the comments? I dont understand why a space can be used to replace anything other than a alphanumerical, but not a hypen.
(this is not my original solution; just was trying some things out)
Yes, my apologies.
Lets say these 2 lines of code is number1 and the 1 line below it is number2.
number 1:
.replace(/[^A-Za-z0-9]/g, ’ ')
.replace(/\s{1,}/g, “-”)
and
number 2:
.replace(/[^A-Za-z0-9]/g, ‘-’)
Both of these seem to be doing the same exact thing, which is ultimately replacing any non-alphanumberical with a hyphen, but number 2 has one less line of code. When used in my function, number1 does return the correct solution, but number2 does not. Why is this?