1.6 KiB
		
	
	
	
	
	
	
	
			
		
		
	
	
			1.6 KiB
		
	
	
	
	
	
	
	
id, title, challengeType
| id | title | challengeType | 
|---|---|---|
| 587d7dbb367417b2b2512bac | Remove Whitespace from Start and End | 1 | 
Description
Instructions
The
.trim() method would work here, but you'll need to complete this challenge using regular expressions.
Tests
tests:
  - text: <code>result</code> should equal to <code>"Hello, World!"</code>
    testString: assert(result == "Hello, World!", '<code>result</code> should equal to <code>"Hello, World!"</code>');
  - text: You should not use the <code>.trim()</code> method.
    testString: assert(!code.match(/\.trim\(.*?\)/), 'You should not use the <code>.trim()</code> method.');
  - text: The <code>result</code> variable should not be set equal to a string.
    testString: assert(!code.match(/result\s*=\s*".*?"/), 'The <code>result</code> variable should not be set equal to a string.');
Challenge Seed
let hello = "   Hello, World!  ";
let wsRegex = /change/; // Change this line
let result = hello; // Change this line
Solution
let hello = "   Hello, World!  ";
let wsRegex = /^(\s+)(.+[^\s])(\s+)$/;
let result = hello.replace(wsRegex, '$2');