Correct solution and passes every test in console but keep telling its not.
// the global variable
var globalTitle = "Winter Is Coming";
// Add your code below this line
function urlSlug(title) {
return title.toLowerCase().split(/\W+/).join('-');
}
// Add your code above this line
var winterComing = urlSlug(globalTitle); // Should be "winter-is-coming"
console.log(winterComing);
If you split the string using /[\s.,’-]/gi regex expression , then returned array would be ["", “winter”, “is”, “coming”], since empty strings = to false, you can use filter method, to filter them out.
—working solution—
var globalTitle = "Winter Is Coming";
function urlSlug(title) {
return title.toLowerCase().split(/[\s.,'-]/gi).filter((x) => x).join("-");
}
var winterComing = urlSlug(globalTitle);