* fix: restructure certifications guide articles * fix: added 3 dashes line before prob expl * fix: added 3 dashes line before hints * fix: added 3 dashes line before solutions
1001 B
1001 B
title
title |
---|
Apply Functional Programming to Convert Strings to URL Slugs |
Apply Functional Programming to Convert Strings to URL Slugs
Solutions
Solution 1 (Click to Show/Hide)
// the global variable
var globalTitle = "Winter Is Coming";
// Add your code below this line
function urlSlug(title) {
return title
.split(/\W/)
.filter(obj => {
return obj !== "";
})
.join("-")
.toLowerCase();
}
// Add your code above this line
var winterComing = urlSlug(globalTitle); // Should be "winter-is-coming"
Solution 2 (Click to Show/Hide)
// the global variable
var globalTitle = "Winter Is Coming";
// Add your code below this line
function urlSlug(title) {
return title
.toLowerCase()
.trim()
.split(/\s+/)
.join("-");
}
// Add your code above this line
var winterComing = urlSlug(globalTitle); // Should be "winter-is-coming"