Remove Whitespace from Start and End I passed, but

Remove Whitespace from Start and End I passed, but
0

#1

Tell us what’s happening:
I passed this challenge, but it does not seem what I did was what I learned from previous challenges. So I am afraid that I did it in a wrong way and I happened to pass it.
Can anybody let me know if there is something wrong with my code and what I should do in stead?

Your code so far


let hello = "   Hello, World!  ";
let wsRegex = /\S+\s\S+/; // Change this line
let result = hello.match(wsRegex); // Change this line

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/remove-whitespace-from-start-and-end


#2

The task is trimming spaces from left and right. Here are some troubles you might face with the current code.

If there are more than one space between the words.

"    Hello,      world       "

If you need to trim a sentence with more than 2 words.

"    Hello, world again!     "

Don’t feel that you need to use everything you have learned. Just solve the problem and find ways to make it better in a way that you’d still understand the solution. Also, don’t let the test result provided by FCC fool you; evaluate the solution yourself.

In this case, being more faithful to the definition of trimming results simpler and less error prone code.