Why doesnā€™t split(ā€œ ā€œ) work, while split(/\s+/) does? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 2

Why doesnā€™t split(ā€œ ā€œ) work, while split(/\s+/) does?

Hello, I was solving a JavaScript coding problem on freeCodeCamp and submitted my solution (code attached in this post). Unluckily my solution hasnā€™t been accepted even though the output in the console is the expected one.Ā  The solution of FCC is the same as my code, but instead of split(ā€œ ā€), they used split(/\s+/), using a regex in parenthesis. My question is: in this case technically split(ā€œ ā€œ) should be correct, right? If not, could you kindly explain to me why? Thanks in advance. P.S. Original problem can be found at the following link: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs https://code.sololearn.com/c2E9SfEicL1U/?ref=app https://code.sololearn.com/c2E9SfEicL1U/?ref=app https://code.sololearn.com/c2E9SfEicL1U/?ref=app

15th Aug 2022, 9:25 AM
krssclaire
krssclaire - avatar
2 Respostas
+ 6
krssclaire There might be more spaces between 2 words like: abc xyz so in this case split(" ") may not work because you have given a single space in split function. Just try to give more space in your code String and see effect.
15th Aug 2022, 9:42 AM
AĶ¢J
AĶ¢J - avatar
+ 2
AĶ¢J Aaah yes, just tried, thank you so much!
15th Aug 2022, 9:54 AM
krssclaire
krssclaire - avatar