Apply-functional-programming-to-convert-strings-to-url-slugs


return title.toLowerCase().trim().split(/\W+/).join("-");

It works for me!

I don’t see where this question was ever addressed or reposted. I don’t know what was unclear about the question. It seems pretty strait forward: what is !='' doing here? the link you gave him is one we have all visited multiple time at this point in the course and doesn’t address the question. Any insight into the answer or the refusal to address the question would be enlightening.

OK yeah. Sorry if I sounded a little cranky. “refusal” is not the best connotation. I always want to learn more about how to best phrase questions here-one of the hardest things actually. I was reading it as "Item Is not an ‘empty array’. In context of .filter here its not an array, but an element empty space that you don’t want returned in the altered array. Any extra whitespace would need to be dealt with…I think I just needed a break to understand it.
Thanks Randall,
MP

This worked for me.

// Only change code below this line

var globalTitle = "Winter Is Coming";

function urlSlug(title) {
    
   return title.toLowerCase().trim().split(/\s+/).join("-");

}
// Only change code above this line

var winterComing = urlSlug(globalTitle);
console.log(winterComing);

Hey @sitiveh!
Welcome to the Forum!

This topic is inactive for 4 months, I suggest you to Create a new topic.

Hi @sitiveh!

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

1 Like