Problem with urlSlug()

Tell us what’s happening:

**Your code so far**

function urlSlug(title) {// Only change code below this line
var splitted=title.toLowerCase().split(/\s/);
for(let i=0; i<splitted.length; i++){
    let arr=[...splitted];
    arr.splice(arr.indexOf(""), 1);
    return arr.join("-");
    return splitted.join("-");
// Only change code above this line
console.log(urlSlug(" Winter Is Coming"))
**Your browser information:**

User Agent is: Mozilla/5.0 (Linux; U; Android 7.0; TECNO P701 Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/88.0.4324.181 Mobile Safari/537.36 OPR/24.0.2254.115784.

Challenge: Apply Functional Programming to Convert Strings to URL Slugs

Link to the challenge:

So, the problem is the input " Winter Is Coming" (note the extra space in between “is” and “coming”) is returning winter-is--coming.

So, the problem is that

var splitted = title.toLowerCase().split(/\s/);
// ["", "winter", "is", "", "coming"]

Notice the 4th element. So, split is seeing that extra space and is creating an empty string element. There are a couple of ways to fix this. The most elegant would be to fix it at the source by adjusting the regex. In regex there are quantifiers that tell it how many of “whatever” to match. By default, this is matching one character that fits \d. There is a quantifier that will tell it to match “one or more”. With that, I can fix your code by adding one character.

Can you find it? Let us know if you need more of a hint.

Please continue with it.

I don’t understand. Are you asking for more clues? Can you show me what you’ve tried? I might suggest a reference on regex quantifiers.

okay let me try the reference