Convert Strings to URL Slugs Global Variable

Convert Strings to URL Slugs Global Variable
0

#1

Hi all,

I’ve managed to complete this challenge except for the fact that I’m failing the “The globalTitle variable should not change.” I’m scratching my head here. What part of my code is changing the global variable?

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

// Add your code below this line
function urlSlug(title) {
  let slug = title.slice();
  return slug.toLowerCase().split(/\W/).filter((item) => item.length > 0).join("-");
}
// Add your code above this line

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

Thanks in advance!

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


#2

Check the link below!


#3

Nothing in your code modifies argument to me, even if you would have removed .slice() line completely and return title.... you still wouldn’t change it.

Two notes:

  1. You might want /\W+/ just in case there are more then one non-word character
  2. You might want to trim() argument as well :wink:

#4

Thanks, worked like a charm! That /\W+/ let me get rid of that filter method.