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:
Hassaan Pasha
2020-09-17 19:08:01 +05:00
committed by GitHub
parent aecbc28798
commit 80438cac3e
54 changed files with 326 additions and 157 deletions

View File

@@ -38,7 +38,7 @@ tests:
- text: <code>copyMachine(["it works"], 3)</code> should return <code>[["it works"], ["it works"], ["it works"]]</code>
testString: assert.deepEqual(copyMachine(['it works'], 3), [['it works'], ['it works'], ['it works']]);
- text: The <code>copyMachine</code> function should utilize the <code>spread operator</code> with array <code>arr</code>
testString: assert(removeJSComments(code).match(/\.\.\.arr/));
testString: assert(__helpers.removeJSComments(code).match(/\.\.\.arr/));
```
@@ -66,15 +66,6 @@ console.log(copyMachine([true, false, true], 2));
</div>
### After Test
<div id='js-teardown'>
```js
const removeJSComments = str => str.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, '');
```
</div>
</section>
## Solution

View File

@@ -42,13 +42,13 @@ We've initialized an array `arr`. Use `splice()` to remove elements from `arr`,
```yml
tests:
- text: You should not change the original line of <code>const arr = [2, 4, 5, 1, 7, 5, 2, 1];</code>.
testString: assert(code.replace(/\s/g, '').match(/constarr=\[2,4,5,1,7,5,2,1\];?/));
testString: assert(__helpers.removeWhiteSpace(code).match(/constarr=\[2,4,5,1,7,5,2,1\];?/));
- text: <code>arr</code> should only contain elements that sum to <code>10</code>.
testString: assert.strictEqual(arr.reduce((a, b) => a + b), 10);
- text: Your code should utilize the <code>splice()</code> method on <code>arr</code>.
testString: assert(code.replace(/\s/g, '').match(/arr\.splice\(/));
testString: assert(__helpers.removeWhiteSpace(code).match(/arr\.splice\(/));
- text: The splice should only remove elements from <code>arr</code> and not add any additional elements to <code>arr</code>.
testString: assert(!code.replace(/\s/g, '').match(/arr\.splice\(\d+,\d+,\d+.*\)/g));
testString: assert(!__helpers.removeWhiteSpace(code).match(/arr\.splice\(\d+,\d+,\d+.*\)/g));
```
</section>