fix: improved existing tests (#35801)

This commit is contained in:
Randell Dawson
2019-05-09 06:01:50 -07:00
committed by Manish Giri
parent 7b4e8632f5
commit 7437145bb4

View File

@ -6,7 +6,7 @@ challengeType: 1
## Description
<section id='description'>
A side effect of the <code>sort</code> method is that it changes the order of the elements in the original array. In other words, it mutates the array in place. One way to avoid this is to first concatenate an empty array to the one being sorted (remember that <code>concat</code> returns a new array), then run the <code>sort</code> method.
A side effect of the <code>sort</code> method is that it changes the order of the elements in the original array. In other words, it mutates the array in place. One way to avoid this is to first concatenate an empty array to the one being sorted (remember that <code>slice</code> and <code>concat</code> return a new array), then run the <code>sort</code> method.
</section>
## Instructions
@ -20,13 +20,13 @@ Use the <code>sort</code> method in the <code>nonMutatingSort</code> function to
```yml
tests:
- text: Your code should use the <code>sort</code> method.
testString: assert(code.match(/\.sort/g), 'Your code should use the <code>sort</code> method.');
- text: Your code should use the <code>concat</code> method.
testString: assert(code.match(/\.concat/g), 'Your code should use the <code>concat</code> method.');
testString: assert(nonMutatingSort.toString().match(/\.sort/g));
- text: The <code>globalArray</code> variable should not change.
testString: assert(JSON.stringify(globalArray) === JSON.stringify([5, 6, 3, 2, 9]), 'The <code>globalArray</code> variable should not change.');
testString: assert(JSON.stringify(globalArray) === JSON.stringify([5, 6, 3, 2, 9]));
- text: <code>nonMutatingSort(globalArray)</code> should return <code>[2, 3, 5, 6, 9]</code>.
testString: assert(JSON.stringify(nonMutatingSort(globalArray)) === JSON.stringify([2, 3, 5, 6, 9]), '<code>nonMutatingSort(globalArray)</code> should return <code>[2, 3, 5, 6, 9]</code>.');
testString: assert(JSON.stringify(nonMutatingSort(globalArray)) === JSON.stringify([2, 3, 5, 6, 9]));
- text: <code>nonMutatingSort(globalArray)</code> should not be hard coded.
testString: assert(!nonMutatingSort.toString().match(/[23569]/g));
```