Help me to Convert Strings to URL Slugs in javascript

Tell us what’s happening:

Hello everyone!
I wrote this solution to end the challenge, the problem is that it creates a dash also on the last word and, when it finds a phrase with a space, it inserts two dashes instead of one. Can you explain and make me understand how to solve and where am I wrong?

Thank you

Your code so far

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

// Add your code below this line
function urlSlug(title) {
let newStr;
newStr = title.toLowerCase()
.split(' ')
.map((el, index) => el + '-')

// Add your code above this line

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

Challenge: Apply Functional Programming to Convert Strings to URL Slugs

Link to the challenge:


//... .split().map().join()


//... .split(' ').join('-')
1 Like

Thanks so much!
Sometimes I get lost in a glass of water! :sweat_smile: