feat(client, learn): add helper functions for common validation operations (#38605)
Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com>
This commit is contained in:
@ -39,7 +39,7 @@ tests:
|
||||
- text: <code>myData</code> should be equal to <code>8</code>.
|
||||
testString: assert(myData === 8);
|
||||
- text: You should be using bracket notation to read the correct value from <code>myArray</code>.
|
||||
testString: assert(/myData=myArray\[2\]\[1\]/.test(code.replace(/\s/g, '')));
|
||||
testString: assert(/myData=myArray\[2\]\[1\]/.test(__helpers.removeWhiteSpace(code)));
|
||||
|
||||
```
|
||||
|
||||
|
@ -37,7 +37,7 @@ tests:
|
||||
- text: You should use a <code>for</code> loop to iterate through <code>myArr</code>.
|
||||
testString: assert(/for\s*\(/g.test(code) && /myArr\s*\[/g.test(code));
|
||||
- text: You should not attempt to directly assign the value 20 to <code>total</code>.
|
||||
testString: assert(!code.replace(/\s/g, '').match(/total[=+-]0*[1-9]+/gm));
|
||||
testString: assert(!__helpers.removeWhiteSpace(code).match(/total[=+-]0*[1-9]+/gm));
|
||||
```
|
||||
|
||||
</section>
|
||||
|
@ -43,7 +43,7 @@ tests:
|
||||
}
|
||||
assert.throws(declared, ReferenceError);
|
||||
- text: You should add a local <code>myVar</code> variable.
|
||||
testString: assert(/functionmyLocalScope\(\)\{.+(var|let|const)myVar[\s\S]*}/.test(code.replace(/\s/g, '')));
|
||||
testString: assert(/functionmyLocalScope\(\)\{.+(var|let|const)myVar[\s\S]*}/.test(__helpers.removeWhiteSpace(code)));
|
||||
|
||||
|
||||
```
|
||||
|
@ -57,9 +57,9 @@ tests:
|
||||
- text: <code>sum([2, 3, 4, 5], 3)</code> should equal 9.
|
||||
testString: assert.equal(sum([2, 3, 4, 5], 3), 9);
|
||||
- text: Your code should not rely on any kind of loops (<code>for</code> or <code>while</code> or higher order functions such as <code>forEach</code>, <code>map</code>, <code>filter</code>, or <code>reduce</code>.).
|
||||
testString: assert(!removeJSComments(code).match(/for|while|forEach|map|filter|reduce/g));
|
||||
testString: assert(!__helpers.removeJSComments(code).match(/for|while|forEach|map|filter|reduce/g));
|
||||
- text: You should use recursion to solve this problem.
|
||||
testString: assert(removeJSComments(sum.toString()).match(/sum\(.*\)/g).length > 1);
|
||||
testString: assert(__helpers.removeJSComments(sum.toString()).match(/sum\(.*\)/g).length > 1);
|
||||
```
|
||||
|
||||
</section>
|
||||
@ -80,16 +80,6 @@ function sum(arr, n) {
|
||||
|
||||
</div>
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
const removeJSComments = str => str.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, '');
|
||||
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
|
@ -33,7 +33,7 @@ tests:
|
||||
- text: The variable <code>difference</code> should be equal to 12.
|
||||
testString: assert(difference === 12);
|
||||
- text: You should only subtract one number from 45.
|
||||
testString: assert(/difference=45-33;?/.test(code.replace(/\s/g, '')));
|
||||
testString: assert(/difference=45-33;?/.test(__helpers.removeWhiteSpace(code)));
|
||||
```
|
||||
|
||||
</section>
|
||||
|
@ -39,7 +39,7 @@ tests:
|
||||
- text: Returned value from <code>addFive</code> should be <code>undefined</code>.
|
||||
testString: assert(addFive() === undefined);
|
||||
- text: Inside the <code>addFive</code> function, you should add <code>5</code> to the <code>sum</code> variable.
|
||||
testString: assert(addFive.toString().replace(/\s/g, '').match(/sum=sum\+5|sum\+=5/));
|
||||
testString: assert(__helpers.removeWhiteSpace(addFive.toString()).match(/sum=sum\+5|sum\+=5/));
|
||||
|
||||
```
|
||||
|
||||
|
@ -52,9 +52,9 @@ tests:
|
||||
- text: <code>countdown(5)</code> should return <code>[5, 4, 3, 2, 1]</code>
|
||||
testString: assert.deepStrictEqual(countdown(5), [5, 4, 3, 2, 1]);
|
||||
- text: Your code should not rely on any kind of loops (<code>for</code>, <code>while</code> or higher order functions such as <code>forEach</code>, <code>map</code>, <code>filter</code>, and <code>reduce</code>).
|
||||
testString: assert(!removeJSComments(code).match(/for|while|forEach|map|filter|reduce/g));
|
||||
testString: assert(!__helpers.removeJSComments(code).match(/for|while|forEach|map|filter|reduce/g));
|
||||
- text: You should use recursion to solve this problem.
|
||||
testString: assert(removeJSComments(countdown.toString()).match(/countdown\s*\(.+\)/));
|
||||
testString: assert(__helpers.removeJSComments(countdown.toString()).match(/countdown\s*\(.+\)/));
|
||||
```
|
||||
|
||||
</section>
|
||||
@ -76,15 +76,6 @@ function countdown(n){
|
||||
|
||||
</div>
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
const removeJSComments = str => str.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, '');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
|
@ -25,9 +25,9 @@ tests:
|
||||
- text: Your function should return an array.
|
||||
testString: assert(Array.isArray(rangeOfNumbers(5, 10)));
|
||||
- text: Your code should not use any loop syntax (<code>for</code> or <code>while</code> or higher order functions such as <code>forEach</code>, <code>map</code>, <code>filter</code>, or <code>reduce</code>).
|
||||
testString: assert(!removeJSComments(code).match(/for|while|forEach|map|filter|reduce/g));
|
||||
testString: assert(!__helpers.removeJSComments(code).match(/for|while|forEach|map|filter|reduce/g));
|
||||
- text: <code>rangeOfNumbers</code> should use recursion (call itself) to solve this challenge.
|
||||
testString: assert(removeJSComments(rangeOfNumbers.toString()).match(/rangeOfNumbers\s*\(.+\)/));
|
||||
testString: assert(__helpers.removeJSComments(rangeOfNumbers.toString()).match(/rangeOfNumbers\s*\(.+\)/));
|
||||
- text: <code>rangeOfNumbers(1, 5)</code> should return <code>[1, 2, 3, 4, 5]</code>.
|
||||
testString: assert.deepStrictEqual(rangeOfNumbers(1, 5), [1, 2, 3, 4, 5]);
|
||||
- text: <code>rangeOfNumbers(6, 9)</code> should return <code>[6, 7, 8, 9]</code>.
|
||||
@ -51,15 +51,6 @@ function rangeOfNumbers(startNum, endNum) {
|
||||
|
||||
</div>
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
const removeJSComments = str => str.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, '');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
|
Reference in New Issue
Block a user