mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-13 22:00:19 -04:00
chore(curriculum): update merge sort tests (#57182)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user