Functional Programming - Apply Functional Programming to Convert Strings to URL Slugs

Tell us what’s happening:
i am thinking this should have worked specifically FOR the multiple white space dilemma on
test 3 = winter is coming…
but it does not… wondering why?

Your code so far

// Only change code below this line
function urlSlug(title) {
  let control = /\s{1,}/g;

  let newStr1 = title.toLowerCase()
  let arr = newStr1.split(control); 

  let slug = arr.join("-")
  return slug


}
// Only change code above this line
urlSlug("A Mind Needs Books Like A Sword Needs A Whetstone");

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36

Challenge: Functional Programming - Apply Functional Programming to Convert Strings to URL Slugs

Link to the challenge:

Your solution works fine as is. The problem is the leading and trailing whitespace. If you log your function you will see that the whitespace from the beginning of the string is also being joined with a "-". Your solution is good, but what could you use to get rid of leading and trailing whitespace?

lets read from test cases,

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

in your attempted solution you are not “taking care of any leading Spaces”, consider doing that on your “newStr1” variable (shown below)

  • try looking into “trim”

happy learning :slight_smile:

1 Like

hadnt seen this… i get ya… thank you
:star_struck: :smiling_face: :blush:

much appreciated
:star_struck: :star_struck: :smiling_face:

1 Like

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