Challenge apply-functional-programming-to-convert-strings-to-url-slugs has an issue.
// the global variable
var globalTitle = "Winter Is Coming";
// Add your code below this line
function urlSlug(title) {
return title.trim()
.split(' ')
.map(word => word.toLowerCase())
.join('-');
}; // <-- This triggers the linter
// Add your code above this line
var winterComing = urlSlug(globalTitle); // Should be "winter-is-coming"
The editor's linter complains about an unnecessary semicolon - see the comment in the code above.
If you want to fix this, please read CONTRIBUTING.md to get started.
When you're all set, replace this line with the following, and make your commit.
"}",
If you have any questions, please come chat with us in the Contributors Chat Room.
Happy Coding! :smile:
Hi, @Greenheart. Can I work on it? It is my first time. Thank you
@Quinn-H Sure! :smile:
i would like to help a bit i am not the best but i am good at finding bugs let me know if i can help
@bigkatspence This issue is assigned to @Quinn-H, but if you want to help out, there's plenty of things that we really would appreciate:
Or, the most fun one: Help beta-test the new curriculum over at https://beta.freecodecamp.com and report any bugs you find here. This is a great way to learn new things while getting open source contributions.
Hope that helps! If you need anything, please come chat with us in /Contributors on Gitter.
Happy coding! :smile:
Hi, @Greenheart I deleted Unnecessary semicolon and created a pull request. Thank you. And I also found the answer you wrote for this challenge isn't right, you forgot filter()
out extra space before join('-')
see below:
// the global variable
var globalTitle = "Winter Is Coming";
// Add your code below this line
function urlSlug(title) {
return title.trim()
.split(' ')
.map(word => word.toLowerCase())
.filter(words => words !== '')
.join('-');
} // <-- This triggers the linter
// Add your code above this line
var winterComing = urlSlug(globalTitle); // Should be "winter-is-coming"
@Quinn-H Thanks for helping out! :smile:
I solved it by splitting on /\s+/
instead of jsut ' '
. This way, it still splits by words but can handle extra spaces. I also made a copy of the string using slice()
to not mutate the original when i use trim()
:blush:
// the global variable
var globalTitle = "Winter Is Coming";
// Add your code below this line
function urlSlug(title) {
return title.slice()
.trim()
.split(/\s+/)
.map(word => word.toLowerCase())
.join('-');
}
// Add your code above this line
var winterComing = urlSlug(globalTitle); // Should be "winter-is-coming"
Most helpful comment
Hi, @Greenheart I deleted Unnecessary semicolon and created a pull request. Thank you. And I also found the answer you wrote for this challenge isn't right, you forgot
filter()
out extra space beforejoin('-')
see below: