Trouble with converting to url slugs challenge

I tried my best to make it work but for some reason the .trim doesn’t shave off the first extra space. If anyone has some advice or a tip please let me know. Thanks!

Your code so far


// Only change code below this line
function urlSlug(title) {


let slu = title.trim().toLowerCase().split(' ').join('-');

return slu;

}
// 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/92.0.4515.131 Safari/537.36 Edg/92.0.902.73

Challenge: Apply Functional Programming to Convert Strings to URL Slugs

Link to the challenge:

The problem isn’t the first space:

function urlSlug(title) {
  let slu = title
    .trim()
    .toLowerCase()
    .split(' ')
    .join('-');
  return slu;
}

console.log(urlSlug(" Winter Is  Coming")); // winter-is--coming

Ohhhhhh, ok thanks a bucket LOL :laughing:

I hadn’t run a console.log so I should probably start doing that more often

1 Like

What would you recommend I try? I feel like .filter or REGEX is my best option.

Since you’ve got a pretty good functional approach going, I’d go with ‘filter’. The callback function actually ends up being really straightforward once you see what it is :slight_smile:

1 Like

Ok thanks, Imma take a break from this to get some of my other tasks done but hopefully I’ll come back later tonight with some fresh eyes :grinning_face_with_smiling_eyes:

Thanks!

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.