Convert Strings to URL Slugs output seems correct

The output trims the white space but for some reason it doesn’t pass the test. Perhaps its due to the regex ?

Your code so far


// The global variable
var globalTitle = " Winter Is Coming";

// Only change code below this line
function urlSlug(title) {
return title
    .trim()
    .toLowerCase()
    .split(/\b\W/)
    .join('-')     // output is 'winter-is-coming' but doesn't pass test

}
// Only change code above this line

var winterComing = urlSlug(globalTitle); // Should be "winter-is-coming"

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36.

Challenge: Apply Functional Programming to Convert Strings to URL Slugs

Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs

Take a look at the answer for the not passing case, it should make clear what is wrong.

console.log(urlSlug(" Winter Is  Coming"));

you have changed this, that will make the test fail

Thanks Sanity,

I was so focused on the space at the beginning of the string. So I overlooked the double space between the two words. Sometimes its those little things!

The following solution works:

function urlSlug(title) {
return title
.trim()
.toLowerCase()
.split(/\b\W\s*/)
.join(’-’)

}