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:
@ -24,9 +24,9 @@ tests:
|
||||
- text: <code>squareList</code> should be a <code>function</code>.
|
||||
testString: assert.typeOf(squareList, 'function'), '<code>squareList</code> should be a <code>function</code>';
|
||||
- text: for or while loops or forEach should not be used.
|
||||
testString: assert(!removeJSComments(code).match(/for|while|forEach/g));
|
||||
testString: assert(!__helpers.removeJSComments(code).match(/for|while|forEach/g));
|
||||
- text: <code>map</code>, <code>filter</code>, or <code>reduce</code> should be used.
|
||||
testString: assert(removeJSComments(code).match(/\.(map|filter|reduce)\s*\(/g));
|
||||
testString: assert(__helpers.removeJSComments(code).match(/\.(map|filter|reduce)\s*\(/g));
|
||||
- text: The function should return an <code>array</code>.
|
||||
testString: assert(Array.isArray(squareList([4, 5.6, -9.8, 3.14, 42, 6, 8.34, -2])));
|
||||
- text: <code>squareList([4, 5.6, -9.8, 3.14, 42, 6, 8.34, -2])</code> should return <code>[16, 1764, 36]</code>.
|
||||
@ -55,14 +55,6 @@ console.log(squaredIntegers);
|
||||
|
||||
</div>
|
||||
|
||||
<div id='js-teardown'>
|
||||
|
||||
```js
|
||||
const removeJSComments = str => str.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, '');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
|
@ -41,7 +41,7 @@ tests:
|
||||
- text: The <code>watchList</code> variable should not change.
|
||||
testString: assert(watchList[0].Title === "Inception" && watchList[4].Director == "James Cameron");
|
||||
- text: Your code should not use a <code>for</code> loop.
|
||||
testString: assert(!removeJSComments(code).match(/for\s*?\([\s\S]*?\)/));
|
||||
testString: assert(!__helpers.removeJSComments(code).match(/for\s*?\([\s\S]*?\)/));
|
||||
- text: Your code should use the <code>map</code> method.
|
||||
testString: assert(code.match(/\.map/g));
|
||||
- text: <code>ratings</code> should equal <code>[{"title":"Inception","rating":"8.8"},{"title":"Interstellar","rating":"8.6"},{"title":"The Dark Knight","rating":"9.0"},{"title":"Batman Begins","rating":"8.3"},{"title":"Avatar","rating":"7.9"}]</code>.
|
||||
@ -185,15 +185,6 @@ console.log(JSON.stringify(ratings));
|
||||
|
||||
</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