Functional Programming: Convert Strings to URL Slugs

Using the following code:

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

The test is returning the following problem:

urlSlug(" Winter Is Coming") should return "winter-is-coming".

But if I run the code in console or in jsbin, it returns the proper result, so it looks to be working?

Is this an actual issue with the unit test provided, or am I somehow bypassing the issue when I test it by hand? Thanks for any assistance!

Notice this test case has some space infront.

So splitting will actually add a dash to the front of your array.

1 Like

Dear lord. It was the one with multiple spaces between Is and Coming (Somehow I didn’t get that copied in correctly), so I tunneled in on that. Thanks for the answer!

1 Like