Or how can I use .replace() funct in this solution?
// The global variable
var globalTitle = "Winter Is Coming";
// Only change code below this line
function urlSlug(title) {
return title
.toLowerCase()
.split(" ")
.replace(/^\s+|\s+$/g, "") // Why I can't use .replace() here?
.join("-");
}
// Only change code above this line
console.log(urlSlug(" Winter Is Coming"));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36.
Challenge: Apply Functional Programming to Convert Strings to URL Slugs
there will be no spaces there, as you have already remvoed all spaces using split as previous method
there are array methods like map or filter that depending on how you use them could do what you need
maybe instead of going to try every possible method, think at the steps you want to take, write them down in plain language, and once you have clear all the steps, then work in converting it to an algorithm