Apply Functional Programming to Convert Strings to URL Slugs using trim()

Tell us what’s happening:
tests not pass

The elusive test " Winter is coming" fails. But doing the string.trim() i thought would be sufficient to remove white space from the string. It also appears to have done so when I look at the text editor. Because the resulting string is “winter-is-coming”. But for some reason the test still is not satisfied.
Your code so far

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

// Add your code below this line
function urlSlug(title) {
  let word = title.toLowerCase();
  word = word.trim();
  word = word.split(' ');
  word = word.join('-');
  return word;
// 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; rv:66.0) Gecko/20100101 Firefox/66.0.

Which test are you failing?

The one most fail that has a space at the beginning. Most people forget to take that out. But i am pretty sure that’s not my problem .

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

The one that should be failing is the test where there are sequential spaces inside the string.

1 Like

word = word.split(/\s+/);
absolutely right. Didn’t notice the extra spaces in the middle.

Put some extra space in it ! XD Didn’t see it too, I wandered in the dark till decided to open topic and saw there was one already ! Damn it!