bug fix / test of Spread Operator javascript challenge / english (#35856)
* bug fix test with the Spread Operator * test of Spread Operator javascript challenge / english / change test and add a helper function
This commit is contained in:
		| @@ -22,15 +22,15 @@ We have defined a function, <code>copyMachine</code> which takes <code>arr</code | |||||||
| ```yml | ```yml | ||||||
| tests: | tests: | ||||||
|   - text: <code>copyMachine([true, false, true], 2)</code> should return <code>[[true, false, true], [true, false, true]]</code> |   - text: <code>copyMachine([true, false, true], 2)</code> should return <code>[[true, false, true], [true, false, true]]</code> | ||||||
|     testString: assert.deepEqual(copyMachine([true, false, true], 2), [[true, false, true], [true, false, true]], '<code>copyMachine([true, false, true], 2)</code> should return <code>[[true, false, true], [true, false, true]]</code>'); |     testString: assert.deepEqual(copyMachine([true, false, true], 2), [[true, false, true], [true, false, true]]); | ||||||
|   - text: <code>copyMachine([1, 2, 3], 5)</code> should return <code>[[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3]]</code> |   - text: <code>copyMachine([1, 2, 3], 5)</code> should return <code>[[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3]]</code> | ||||||
|     testString: assert.deepEqual(copyMachine([1, 2, 3], 5), [[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3]], '<code>copyMachine([1, 2, 3], 5)</code> should return <code>[[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3]]</code>'); |     testString: assert.deepEqual(copyMachine([1, 2, 3], 5), [[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3]]); | ||||||
|   - text: <code>copyMachine([true, true, null], 1)</code> should return <code>[[true, true, null]]</code> |   - text: <code>copyMachine([true, true, null], 1)</code> should return <code>[[true, true, null]]</code> | ||||||
|     testString: assert.deepEqual(copyMachine([true, true, null], 1), [[true, true, null]], '<code>copyMachine([true, true, null], 1)</code> should return <code>[[true, true, null]]</code>'); |     testString: assert.deepEqual(copyMachine([true, true, null], 1), [[true, true, null]]); | ||||||
|   - text: <code>copyMachine(["it works"], 3)</code> should return <code>[["it works"], ["it works"], ["it works"]]</code> |   - 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']], '<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> |   - text: The <code>copyMachine</code> function should utilize the <code>spread operator</code> with array <code>arr</code> | ||||||
|     testString: assert.notStrictEqual(copyMachine.toString().indexOf('.concat(_toConsumableArray(arr))'), -1, 'The <code>copyMachine</code> function should utilize the <code>spread operator</code> with array <code>arr</code>'); |     testString: assert(removeJSComments(code).match(/\.\.\.arr/)); | ||||||
|  |  | ||||||
| ``` | ``` | ||||||
|  |  | ||||||
| @@ -59,7 +59,14 @@ console.log(copyMachine([true, false, true], 2)); | |||||||
|  |  | ||||||
| </div> | </div> | ||||||
|  |  | ||||||
|  | ### After Test | ||||||
|  | <div id='js-teardown'> | ||||||
|  |  | ||||||
|  | ```js | ||||||
|  | const removeJSComments = str => str.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, ''); | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | </div> | ||||||
|  |  | ||||||
| </section> | </section> | ||||||
|  |  | ||||||
| @@ -67,6 +74,16 @@ console.log(copyMachine([true, false, true], 2)); | |||||||
| <section id='solution'> | <section id='solution'> | ||||||
|  |  | ||||||
| ```js | ```js | ||||||
| // solution required | function copyMachine(arr,num){ | ||||||
|  | 	let newArr=[]; | ||||||
|  | 	while(num >=1){ | ||||||
|  | 	// change code below this line  | ||||||
|  | 	newArr.push([...arr]); | ||||||
|  | 	//change code above this line | ||||||
|  | 	num--; | ||||||
|  | 	} | ||||||
|  | 	return newArr; | ||||||
|  | } | ||||||
|  | console.log(copyMachine([true, false, true], 2)); | ||||||
| ``` | ``` | ||||||
| </section> | </section> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user