Challenge: Write a regex and use the appropriate string methods to remove whitespace at the beginning and end of strings.
Current Solution:
let hello = " Hello, World! ";
let wsRegex = /^\s+|\s+$/g; // Change this line
let result = hello.replace(wsRegex, ""); // Change this line
Proposed Alternate Solution:
let hello = " Hello, World! ";
let wsRegex = /^(\s*)(.*[^\s])(\s*)$/; // Change this line
let result = hello.replace(wsRegex, "$2"); // Change this line
The proposed alternate solution is not as elegant, but uses capture groups instead of the (x|x) method, which may be helpful to some. Is this a true alternate solution or a case of insufficient testing?