I successfully cheated the last Regular Expression task

I know my solution will only work if the whitespace before and after the text is >= 2 but it came through. Maybe you should add more test strings so it can`t be this solution.

Remove Whitespace

let hello = "   Hello, World!  ";

let wsRegex = /(\s+){2,}/g; // Change this line

let result = hello.replace(wsRegex,""); // Change this line

console.log(result);
1 Like

Yep, would probably be better if the hello string only had one space at the beginning and end so you couldn’t get away with something like this.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.