mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
fix(curriculum): restore Array.prototype.sort after test (#58115)
This commit is contained in:
+8
-3
@@ -82,7 +82,7 @@ assert.sameMembers(
|
||||
`bubbleSort` should not use the built-in `.sort()` method.
|
||||
|
||||
```js
|
||||
assert(isBuiltInSortUsed());
|
||||
assert.isFalse(isBuiltInSortUsed());
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@@ -99,9 +99,14 @@ function isSorted(a){
|
||||
|
||||
function isBuiltInSortUsed(){
|
||||
let sortUsed = false;
|
||||
const temp = Array.prototype.sort;
|
||||
Array.prototype.sort = () => sortUsed = true;
|
||||
bubbleSort([0, 1]);
|
||||
return !sortUsed;
|
||||
try {
|
||||
bubbleSort([0, 1]);
|
||||
} finally {
|
||||
Array.prototype.sort = temp;
|
||||
}
|
||||
return sortUsed;
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
+8
-3
@@ -84,7 +84,7 @@ assert.deepEqual(insertionSort([5, 4, 33, 2, 8]), [2, 4, 5, 8, 33])
|
||||
`insertionSort` should not use the built-in `.sort()` method.
|
||||
|
||||
```js
|
||||
assert(isBuiltInSortUsed());
|
||||
assert.isFalse(isBuiltInSortUsed());
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@@ -101,9 +101,14 @@ function isSorted(a){
|
||||
|
||||
function isBuiltInSortUsed(){
|
||||
let sortUsed = false;
|
||||
const temp = Array.prototype.sort;
|
||||
Array.prototype.sort = () => sortUsed = true;
|
||||
insertionSort([0, 1]);
|
||||
return !sortUsed;
|
||||
try {
|
||||
insertionSort([0, 1]);
|
||||
} finally {
|
||||
Array.prototype.sort = temp;
|
||||
}
|
||||
return sortUsed;
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
+23
-13
@@ -31,13 +31,6 @@ assert.isFunction(mergeSort);
|
||||
`mergeSort` should return a sorted array (least to greatest).
|
||||
|
||||
```js
|
||||
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([
|
||||
@@ -93,17 +86,34 @@ assert.sameMembers(
|
||||
`mergeSort` should not use the built-in `.sort()` method.
|
||||
|
||||
```js
|
||||
function isBuiltInSortUsed(){
|
||||
let sortUsed = false;
|
||||
Array.prototype.sort = () => sortUsed = true;
|
||||
mergeSort([0, 1]);
|
||||
return sortUsed;
|
||||
}
|
||||
assert.isFalse(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;
|
||||
const temp = Array.prototype.sort;
|
||||
Array.prototype.sort = () => sortUsed = true;
|
||||
try {
|
||||
mergeSort([0, 1]);
|
||||
} finally {
|
||||
Array.prototype.sort = temp;
|
||||
}
|
||||
return sortUsed;
|
||||
}
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
|
||||
+8
-3
@@ -80,7 +80,7 @@ assert.sameMembers(
|
||||
`quickSort` should not use the built-in `.sort()` method.
|
||||
|
||||
```js
|
||||
assert(isBuiltInSortUsed());
|
||||
assert.isFalse(isBuiltInSortUsed());
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@@ -97,9 +97,14 @@ function isSorted(a){
|
||||
|
||||
function isBuiltInSortUsed(){
|
||||
let sortUsed = false;
|
||||
const temp = Array.prototype.sort;
|
||||
Array.prototype.sort = () => sortUsed = true;
|
||||
quickSort([0, 1]);
|
||||
return !sortUsed;
|
||||
try {
|
||||
quickSort([0, 1]);
|
||||
} finally {
|
||||
Array.prototype.sort = temp;
|
||||
}
|
||||
return sortUsed;
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
+8
-3
@@ -78,7 +78,7 @@ assert.sameMembers(
|
||||
`selectionSort` should not use the built-in `.sort()` method.
|
||||
|
||||
```js
|
||||
assert(isBuiltInSortUsed());
|
||||
assert.isFalse(isBuiltInSortUsed());
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@@ -95,9 +95,14 @@ function isSorted(a){
|
||||
|
||||
function isBuiltInSortUsed(){
|
||||
let sortUsed = false;
|
||||
const temp = Array.prototype.sort;
|
||||
Array.prototype.sort = () => sortUsed = true;
|
||||
selectionSort([0, 1]);
|
||||
return !sortUsed;
|
||||
try {
|
||||
selectionSort([0, 1]);
|
||||
} finally {
|
||||
Array.prototype.sort = temp;
|
||||
}
|
||||
return sortUsed;
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user