I found the solution - but by accident.
I dont understand what the .filter() does here.
Can someone explain (in the context of this program).
The case here is that when there is a space before a word, without the filter it doesnt pass, otherwise it does just fine. For the FCC editor to pass the program we need to make sure it doesnt include the space in the front. I thought of filtering it after converting it to a list. Just wrote a filter with a list arg(had no idea what exactly to do then ,it was a loose guess) . For some reason when I pressed “run” , it passed. I have no idea what happened. But I do know what the other parts of the code do.
function urlSlug(title){
let array = title
.split(" ")
.filter(list=> list) //what does this do in here???
.join(" ")
let string = array
.toLowerCase()
.split(" ")
.join("-");
return string;
}
console.log(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/97.0.4692.71 Safari/537.36 Edg/97.0.1072.55
Challenge: Apply Functional Programming to Convert Strings to URL Slugs
Link to the challenge: