# Functional Programming: Convert Strings to URL Slugs

**URL:** <https://forum.freecodecamp.org/t/functional-programming-convert-strings-to-url-slugs/235886>\
**Category:** General\
**Created:** [October 24, 2018, 7:57pm UTC](https://forum.freecodecamp.org/t/functional-programming-convert-strings-to-url-slugs/235886 "2018-10-24T19:57:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![KingofRedOnions](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kingofredonions/32/103562_2.png) [@KingofRedOnions](https://forum.freecodecamp.org/u/KingofRedOnions)\
**Post date:** [October 24, 2018, 7:57pm UTC](https://forum.freecodecamp.org/t/functional-programming-convert-strings-to-url-slugs/235886/1 "2018-10-24T19:57:37Z")

</div>

Using the following code:

```auto
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!

---

<div class="post-metadata">

**Author:** ![shimphillip](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/shimphillip/32/158663_2.png) [@shimphillip](https://forum.freecodecamp.org/u/shimphillip)\
**Post date:** [October 24, 2018, 8:05pm UTC](https://forum.freecodecamp.org/t/functional-programming-convert-strings-to-url-slugs/235886/2 "2018-10-24T20:05:42Z")

</div>

Notice this test case has some space infront.

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

---

<div class="post-metadata">

**Author:** ![KingofRedOnions](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kingofredonions/32/103562_2.png) [@KingofRedOnions](https://forum.freecodecamp.org/u/KingofRedOnions)\
**Post date:** [October 24, 2018, 8:15pm UTC](https://forum.freecodecamp.org/t/functional-programming-convert-strings-to-url-slugs/235886/3 "2018-10-24T20:15:35Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 17, 2021, 8:09pm UTC](https://forum.freecodecamp.org/t/functional-programming-convert-strings-to-url-slugs/235886/4 "2021-01-17T20:09:15Z")

</div>

Closed on January 17, 2021, 8:09pm UTC


