From ad54588686ca2bc9850cf561888dd231d376171e Mon Sep 17 00:00:00 2001 From: Anna Date: Mon, 18 Nov 2024 15:45:36 -0500 Subject: [PATCH] chore(curriculum): update merge sort tests (#57182) --- .../algorithms/implement-merge-sort.md | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/curriculum/challenges/english/10-coding-interview-prep/algorithms/implement-merge-sort.md b/curriculum/challenges/english/10-coding-interview-prep/algorithms/implement-merge-sort.md index e6d9660a3a2..0acf2fa88e5 100644 --- a/curriculum/challenges/english/10-coding-interview-prep/algorithms/implement-merge-sort.md +++ b/curriculum/challenges/english/10-coding-interview-prep/algorithms/implement-merge-sort.md @@ -25,13 +25,20 @@ As an aside, this will be the last sorting algorithm we cover here. However, lat `mergeSort` should be a function. ```js -assert(typeof mergeSort == 'function'); +assert.isFunction(mergeSort); ``` `mergeSort` should return a sorted array (least to greatest). ```js -assert( +function isSorted(a){ + for(let i = 0; i < a.length - 1; i++) + if(a[i] > a[i + 1]) + return false; + return true; +} + +assert.isTrue( isSorted( mergeSort([ 1, @@ -86,29 +93,17 @@ assert.sameMembers( `mergeSort` should not use the built-in `.sort()` method. ```js -assert(isBuiltInSortUsed()); -``` - -# --seed-- - -## --after-user-code-- - -```js -function isSorted(a){ - for(let i = 0; i < a.length - 1; i++) - if(a[i] > a[i + 1]) - return false; - return true; -} - function isBuiltInSortUsed(){ let sortUsed = false; Array.prototype.sort = () => sortUsed = true; mergeSort([0, 1]); - return !sortUsed; + return sortUsed; } +assert.isFalse(isBuiltInSortUsed()); ``` +# --seed-- + ## --seed-contents-- ```js