mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-01-26 03:02:39 -05:00
996 B
996 B
title, localeTitle
| title | localeTitle |
|---|---|
| Apply Functional Programming to Convert Strings to URL Slugs | Aplicar programação funcional para converter seqüências de caracteres em URL Slugs |
Aplicar programação funcional para converter seqüências de caracteres em URL Slugs
Solução
// 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"
Solução alternativa
// 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"