refactor(curriculum): remove after-user-code code prep algorithms (#60415)

This commit is contained in:
Anna
2025-05-21 13:12:09 -04:00
committed by GitHub
parent 37b15a1e73
commit 3b86efc8cf
6 changed files with 81 additions and 91 deletions
@@ -41,18 +41,26 @@ const testArray = [
`binarySearch` should be a function.
```js
assert(typeof binarySearch == 'function');
assert.isFunction(binarySearch);
```
`binarySearch(testArray, 0)` should return `[13, 5, 2, 0]`.
```js
const _testArray = [
0, 1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 49, 70
];
assert.deepEqual(binarySearch(_testArray, 0), [13, 5, 2, 0]);
```
`binarySearch(testArray, 1)` should return `[13, 5, 2, 0, 1]`.
```js
const _testArray = [
0, 1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 49, 70
];
assert.deepEqual(binarySearch(_testArray, 1), [13, 5, 2, 0, 1]);
```
@@ -60,44 +68,55 @@ assert.deepEqual(binarySearch(_testArray, 1), [13, 5, 2, 0, 1]);
`binarySearch(testArray, 2)` should return `[13, 5, 2]`.
```js
const _testArray = [
0, 1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 49, 70
];
assert.deepEqual(binarySearch(_testArray, 2), [13, 5, 2]);
```
`binarySearch(testArray, 6)` should return the string `Value Not Found`.
```js
const _testArray = [
0, 1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 49, 70
];
assert.strictEqual(binarySearch(_testArray, 6), 'Value Not Found');
```
`binarySearch(testArray, 11)` should return `[13, 5, 10, 11]`.
```js
const _testArray = [
0, 1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 49, 70
];
assert.deepEqual(binarySearch(_testArray, 11), [13, 5, 10, 11])
```
`binarySearch(testArray, 13)` should return `[13]`.
```js
const _testArray = [
0, 1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 49, 70
];
assert.deepEqual(binarySearch(_testArray, 13), [13]);
```
`binarySearch(testArray, 70)` should return `[13, 19, 22, 49, 70]`.
```js
assert.deepEqual(binarySearch(_testArray, 70), [13, 19, 22, 49, 70]);
```
# --seed--
## --after-user-code--
```js
const _testArray = [
0, 1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 49, 70
];
assert.deepEqual(binarySearch(_testArray, 70), [13, 19, 22, 49, 70]);
```
# --seed--
## --seed-contents--
```js
@@ -21,13 +21,19 @@ This method requires multiple iterations through the array and for average and w
`bubbleSort` should be a function.
```js
assert(typeof bubbleSort == 'function');
assert.isFunction(bubbleSort);
```
`bubbleSort` 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(
bubbleSort([
1,
@@ -82,21 +88,6 @@ assert.sameMembers(
`bubbleSort` should not use the built-in `.sort()` method.
```js
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;
@@ -108,8 +99,11 @@ function isBuiltInSortUsed(){
}
return sortUsed;
}
assert.isFalse(isBuiltInSortUsed());
```
# --seed--
## --seed-contents--
```js
@@ -17,13 +17,19 @@ The next sorting method we'll look at is insertion sort. This method works by bu
`insertionSort` should be a function.
```js
assert(typeof insertionSort == 'function');
assert.isFunction(insertionSort);
```
`insertionSort` 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(
insertionSort([
1,
@@ -84,21 +90,6 @@ assert.deepEqual(insertionSort([5, 4, 33, 2, 8]), [2, 4, 5, 8, 33])
`insertionSort` should not use the built-in `.sort()` method.
```js
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;
@@ -110,8 +101,11 @@ function isBuiltInSortUsed(){
}
return sortUsed;
}
assert.isFalse(isBuiltInSortUsed());
```
# --seed--
## --seed-contents--
```js
@@ -31,6 +31,12 @@ 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([
@@ -86,21 +92,6 @@ assert.sameMembers(
`mergeSort` should not use the built-in `.sort()` method.
```js
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;
@@ -112,8 +103,11 @@ function isBuiltInSortUsed(){
}
return sortUsed;
}
assert.isFalse(isBuiltInSortUsed());
```
# --seed--
## --seed-contents--
```js
@@ -25,7 +25,13 @@ assert(typeof quickSort == 'function');
`quickSort` 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(
quickSort([
1,
@@ -80,21 +86,6 @@ assert.sameMembers(
`quickSort` should not use the built-in `.sort()` method.
```js
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;
@@ -106,8 +97,11 @@ function isBuiltInSortUsed(){
}
return sortUsed;
}
assert.isFalse(isBuiltInSortUsed());
```
# --seed--
## --seed-contents--
```js
@@ -17,13 +17,20 @@ Here we will implement selection sort. Selection sort works by selecting the min
`selectionSort` should be a function.
```js
assert(typeof selectionSort == 'function');
assert.isFunction(selectionSort);
```
`selectionSort` 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(
selectionSort([
1,
@@ -78,21 +85,6 @@ assert.sameMembers(
`selectionSort` should not use the built-in `.sort()` method.
```js
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;
@@ -104,8 +96,11 @@ function isBuiltInSortUsed(){
}
return sortUsed;
}
assert.isFalse(isBuiltInSortUsed());
```
# --seed--
## --seed-contents--
```js