Apply Functional Programming to Convert Strings to URL Slugs-Latest

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

#1

Tell us what’s happening:
Hello everyone, I am getting all the tests passed but the one where the title argument is “urlSlug(” Winter Is Coming") should return “winter-is-coming”."

My current code returns “-winter-is-coming”. I am off by the first hyphen in my return statement.

Any suggestions would be appreciated.

Thanks

Your code so far


// the global variable
var globalTitle = "Winter Is Coming";

// Add your code below this line
function urlSlug(title) {
  let lowerCase = title.toLowerCase();
  let array = lowerCase.split(/\s+/gi);
  let url = array.join("-");
  return url;
}
// Add your code above this line

var winterComing = urlSlug(globalTitle); // Should be "winter-is-coming"

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs


#2

how about using trim() on your string before you do the hyphenation?

String.trim()


#3

Thanks
I used trim before I performed the join method. That passed the test


#4

Yaaay! I got tripped up by that one too. :wink: