Tell us what’s happening:
Why do we need the trim function if there are no spaces at the beginning or end of the strings? I printed the function when the array has two spaces between words and it printed properly, but when I run the program, it doesn’t render properly.
Your code so far
var globalTitle = “Winter Is Coming”;
// Only change code below this line
function urlSlug(title) {
return title
.toLowerCase()
.split(/\s+/)
.join("-");
}
// The global variable
var globalTitle = "Winter Is Coming";
// Only change code below this line
function urlSlug(title) {
return title
.toLowerCase()
.trim()
.split(/\s+/)
.join("-");
}
// Only change code above this line
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36
.
Challenge: Apply Functional Programming to Convert Strings to URL Slugs
Link to the challenge: