diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/return-a-sorted-array-without-changing-the-original-array.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/return-a-sorted-array-without-changing-the-original-array.english.md index 6436346d14..c7375aeb2a 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/return-a-sorted-array-without-changing-the-original-array.english.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/return-a-sorted-array-without-changing-the-original-array.english.md @@ -6,7 +6,7 @@ challengeType: 1 ## Description
-A side effect of the sort 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 concat returns a new array), then run the sort method. +A side effect of the sort 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 slice and concat return a new array), then run the sort method.
## Instructions @@ -20,13 +20,13 @@ Use the sort method in the nonMutatingSort function to ```yml tests: - text: Your code should use the sort method. - testString: assert(code.match(/\.sort/g), 'Your code should use the sort method.'); - - text: Your code should use the concat method. - testString: assert(code.match(/\.concat/g), 'Your code should use the concat method.'); + testString: assert(nonMutatingSort.toString().match(/\.sort/g)); - text: The globalArray variable should not change. - testString: assert(JSON.stringify(globalArray) === JSON.stringify([5, 6, 3, 2, 9]), 'The globalArray variable should not change.'); + testString: assert(JSON.stringify(globalArray) === JSON.stringify([5, 6, 3, 2, 9])); - text: nonMutatingSort(globalArray) should return [2, 3, 5, 6, 9]. - testString: assert(JSON.stringify(nonMutatingSort(globalArray)) === JSON.stringify([2, 3, 5, 6, 9]), 'nonMutatingSort(globalArray) should return [2, 3, 5, 6, 9].'); + testString: assert(JSON.stringify(nonMutatingSort(globalArray)) === JSON.stringify([2, 3, 5, 6, 9])); + - text: nonMutatingSort(globalArray) should not be hard coded. + testString: assert(!nonMutatingSort.toString().match(/[23569]/g)); ```