Functional Programming: Apply Functional Programming to Convert Strings to URL Slugs Buggy

Tell us what’s happening:
Hi, for some reason I cannot pass this challenge despite meeting all requirements.
I have, as usual, double-checked with console.log() - my best friend :wink:

Seems to me like a bug, might be worth reporting.

I copy / paste the solution now in order to proceed tho it’d be nice to know why this happens.

Your code so far


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

// Only change code below this line


function urlSlug(title) {

let newArr = title.slice();

return newArr.split(/\s+/).join("-").toLowerCase();


}


// Only change code above this line
console.log(urlSlug(globalTitle))
console.log(globalTitle)

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0.

Challenge: Apply Functional Programming to Convert Strings to URL Slugs

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

did you respect this line?

Is this a rhethoric question marinated with slight sarcasm or an actual attempt to help me?

The first test will fail if you don’t respect that.

for the test urlSlug(" Winter Is Coming")
you are returning -winter-is-coming
this is because when you do newArr.split(/\s+/) the array resulting is [ '', 'Winter', 'Is', 'Coming' ]

My bad, I really don’t recall changing the global variable. Either way, thanks for pointing out the error.