Updated tests for 'Iterate through an array with a for loop' to ES6 (#19722)

This commit is contained in:
mail-liam
2018-11-09 00:02:21 +11:00
committed by Kristofer Koishigawa
parent cc84d010fd
commit 86be0947b5

View File

@ -22,13 +22,13 @@ Declare and initialize a variable <code>total</code> to <code>0</code>. Use a <c
```yml
tests:
- text: <code>total</code> should be declared and initialized to 0
testString: assert(code.match(/var.*?total\s*=\s*0.*?;/), '<code>total</code> should be declared and initialized to 0');
testString: assert(code.match(/(var|let|const)\s*?total\s*=\s*0.*?;?/), '<code>total</code> should be declared and initialized to 0');
- text: <code>total</code> should equal 20
testString: assert(total === 20, '<code>total</code> should equal 20');
- text: You should use a <code>for</code> loop to iterate through <code>myArr</code>
testString: assert(code.match(/for\s*\(/g).length > 1 && code.match(/myArr\s*\[/), 'You should use a <code>for</code> loop to iterate through <code>myArr</code>');
- text: Do not set <code>total</code> to 20 directly
testString: assert(!code.match(/total[\s\+\-]*=\s*(\d(?!\s*[;,])|[1-9])/g), 'Do not set <code>total</code> to 20 directly');
testString: assert(!code.match(/total[\s\+\-]*=\s*(0(?!\s*[;,]?$)|[1-9])/gm), 'Do not set <code>total</code> to 20 directly');
```
@ -64,6 +64,7 @@ var myArr = [ 2, 3, 4, 5, 6];
```js
(function(){if(typeof total !== 'undefined') { return "total = " + total; } else { return "total is undefined";}})()
```
</div>