Proposed solution for FCC challenge: Remove Whitespace from start and end

This is my proposed solution for the FCC challenge: Remove Whitespace from start and end.

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

That’s code for solution 2.
challenge

Hi again!

I have edited your post to include the details tags and remove the link out of the title.

The moderators will take a look at your solution and decide if it should be added to the guide.

Thanks!

1 Like

I don’t agree with this solution

result has value of

[ 'Hello, World!',
  index: 3,
  input: '   Hello, World!  ',
  groups: undefined ]

I think I am going to report a bug instead, as it should accept only result being equal to Hello, World!

1 Like

Can I know what is the expected value if this is not the correct solution please? Just curious.

1 Like

the expected should be Hello, World!

1 Like

What I mean is that the result should not be a string. And that is satisfied. The input given is exactly the same as the one above. And also the output is desired output. Also the index where the string is found is correct too. I don’t see any mistake in this.

[ 'Hello, World!',
  index: 3,
  input: '   Hello, World!  ',
  groups: undefined ]

The result variable should not be set equal to a string.

1 Like

that means you can’t do result = "Hello, World!"

2 Likes

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