Functional Programming - Apply Functional Programming to Convert Strings to URL Slugs

Tell us what’s happening:

I’ve run my solution against the test but I can’t seem to figure out why my Regex usage doesn’t pass.

Describe your issue in detail here.

I’m supposed to use .split(/\s+/) instead of .split(/\W/) but when I use console log I’m getting the right response for the test that won’t pass:

urlSlug(" Winter Is Coming") should return the string winter-is-coming .

console log = “winter-is-coming”

Your code so far

// Only change code below this line
function urlSlug(title) {
return title.toLowerCase().trim().split(/\W/).join("-")


}
// Only change code above this line
urlSlug(" 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/113.0.0.0 Safari/537.36

Challenge: Functional Programming - Apply Functional Programming to Convert Strings to URL Slugs

Link to the challenge:

trim only removes white space from the start and end of the string.

\W will match the leftover space in the middle of the string.

console.log(title.toLowerCase().trim().split(/\W/))

and join('-') will add the - for the space.


You can split on something else or filter the string.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.