diff --git a/curriculum/challenges/arabic/08-coding-interview-prep/data-structures/implement-heap-sort-with-a-min-heap.arabic.md b/curriculum/challenges/arabic/08-coding-interview-prep/data-structures/implement-heap-sort-with-a-min-heap.arabic.md index e9d3865082..f0e8afb8ec 100644 --- a/curriculum/challenges/arabic/08-coding-interview-prep/data-structures/implement-heap-sort-with-a-min-heap.arabic.md +++ b/curriculum/challenges/arabic/08-coding-interview-prep/data-structures/implement-heap-sort-with-a-min-heap.arabic.md @@ -39,9 +39,11 @@ tests: ```js // check if array is sorted -function isSorted(arr) { - var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1); - return check(0); +function isSorted(a){ + for(let i = 0; i < a.length - 1; i++) + if(a[i] > a[i + 1]) + return false; + return true; } // generate a randomly filled array var array = new Array(); @@ -68,4 +70,5 @@ var MinHeap = function() { ```js // solution required ``` + diff --git a/curriculum/challenges/chinese/08-coding-interview-prep/data-structures/implement-heap-sort-with-a-min-heap.chinese.md b/curriculum/challenges/chinese/08-coding-interview-prep/data-structures/implement-heap-sort-with-a-min-heap.chinese.md index 3d6679b6c8..b08c841f64 100644 --- a/curriculum/challenges/chinese/08-coding-interview-prep/data-structures/implement-heap-sort-with-a-min-heap.chinese.md +++ b/curriculum/challenges/chinese/08-coding-interview-prep/data-structures/implement-heap-sort-with-a-min-heap.chinese.md @@ -40,9 +40,11 @@ tests: ```js // check if array is sorted -function isSorted(arr) { - var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1); - return check(0); +function isSorted(a){ + for(let i = 0; i < a.length - 1; i++) + if(a[i] > a[i + 1]) + return false; + return true; } // generate a randomly filled array var array = new Array(); @@ -69,4 +71,5 @@ var MinHeap = function() { ```js // solution required ``` + diff --git a/curriculum/challenges/english/10-coding-interview-prep/algorithms/implement-bubble-sort.english.md b/curriculum/challenges/english/10-coding-interview-prep/algorithms/implement-bubble-sort.english.md index 67ddd3b124..5196de7b1e 100644 --- a/curriculum/challenges/english/10-coding-interview-prep/algorithms/implement-bubble-sort.english.md +++ b/curriculum/challenges/english/10-coding-interview-prep/algorithms/implement-bubble-sort.english.md @@ -32,7 +32,7 @@ tests: - text: bubbleSort should return an array that is unchanged except for order. testString: assert.sameMembers(bubbleSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]); - text: bubbleSort should not use the built-in .sort() method. - testString: assert(!code.match(/\.\s*sort\s*\(/)); + testString: assert(isBuiltInSortUsed()); ``` @@ -60,10 +60,19 @@ bubbleSort([1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92])
```js -function isSorted(arr) { - var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1); - return check(0); -}; +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; + bubbleSort([0, 1]); + return !sortUsed; +} ```
diff --git a/curriculum/challenges/english/10-coding-interview-prep/algorithms/implement-insertion-sort.english.md b/curriculum/challenges/english/10-coding-interview-prep/algorithms/implement-insertion-sort.english.md index 957839641f..57e2ac44a3 100644 --- a/curriculum/challenges/english/10-coding-interview-prep/algorithms/implement-insertion-sort.english.md +++ b/curriculum/challenges/english/10-coding-interview-prep/algorithms/implement-insertion-sort.english.md @@ -30,7 +30,7 @@ tests: - text: insertionSort should return an array that is unchanged except for order. testString: assert.sameMembers(insertionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]); - text: insertionSort should not use the built-in .sort() method. - testString: assert(!code.match(/\.\s*sort\s*\(/)); + testString: assert(isBuiltInSortUsed()); ``` @@ -58,10 +58,19 @@ insertionSort([1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 9
```js -function isSorted(arr) { - var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1); - return check(0); -}; +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; + insertionSort([0, 1]); + return !sortUsed; +} ```
diff --git a/curriculum/challenges/english/10-coding-interview-prep/algorithms/implement-merge-sort.english.md b/curriculum/challenges/english/10-coding-interview-prep/algorithms/implement-merge-sort.english.md index ed24736b81..48bf39d38e 100644 --- a/curriculum/challenges/english/10-coding-interview-prep/algorithms/implement-merge-sort.english.md +++ b/curriculum/challenges/english/10-coding-interview-prep/algorithms/implement-merge-sort.english.md @@ -34,7 +34,7 @@ tests: - text: mergeSort should return an array that is unchanged except for order. testString: assert.sameMembers(mergeSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]); - text: mergeSort should not use the built-in .sort() method. - testString: assert(!removeJSComments(code).match(/\.\s*sort\s*\(/)); + testString: assert(isBuiltInSortUsed()); ``` @@ -63,12 +63,19 @@ mergeSort([1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]);
```js -const removeJSComments = str => str.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, ''); +function isSorted(a){ + for(let i = 0; i < a.length - 1; i++) + if(a[i] > a[i + 1]) + return false; + return true; +} -function isSorted(arr) { - var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1); - return check(0); -}; +function isBuiltInSortUsed(){ + let sortUsed = false; + Array.prototype.sort = () => sortUsed = true; + mergeSort([0, 1]); + return !sortUsed; +} ```
diff --git a/curriculum/challenges/english/10-coding-interview-prep/algorithms/implement-quick-sort.english.md b/curriculum/challenges/english/10-coding-interview-prep/algorithms/implement-quick-sort.english.md index 4c56ff2137..7e464e2749 100644 --- a/curriculum/challenges/english/10-coding-interview-prep/algorithms/implement-quick-sort.english.md +++ b/curriculum/challenges/english/10-coding-interview-prep/algorithms/implement-quick-sort.english.md @@ -31,7 +31,7 @@ tests: - text: quickSort should return an array that is unchanged except for order. testString: assert.sameMembers(quickSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]); - text: quickSort should not use the built-in .sort() method. - testString: assert(!code.match(/\.?[\s\S]*?sort/)); + testString: assert(isBuiltInSortUsed()); ``` @@ -61,10 +61,19 @@ function quickSort(array) {
```js -function isSorted(arr) { - var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1); - return check(0); -}; +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; + quickSort([0, 1]); + return !sortUsed; +} ```
diff --git a/curriculum/challenges/english/10-coding-interview-prep/algorithms/implement-selection-sort.english.md b/curriculum/challenges/english/10-coding-interview-prep/algorithms/implement-selection-sort.english.md index d5e03340b9..b3cd6b554e 100644 --- a/curriculum/challenges/english/10-coding-interview-prep/algorithms/implement-selection-sort.english.md +++ b/curriculum/challenges/english/10-coding-interview-prep/algorithms/implement-selection-sort.english.md @@ -30,7 +30,7 @@ tests: - text: selectionSort should return an array that is unchanged except for order. testString: assert.sameMembers(selectionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]); - text: selectionSort should not use the built-in .sort() method. - testString: assert(!code.match(/\.\s*sort\s*\(/)); + testString: assert(isBuiltInSortUsed()); ``` @@ -59,10 +59,19 @@ selectionSort([1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 9
```js -function isSorted(arr) { - var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1); - return check(0); -}; +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; + selectionSort([0, 1]); + return !sortUsed; +} ```
diff --git a/curriculum/challenges/english/10-coding-interview-prep/data-structures/implement-heap-sort-with-a-min-heap.english.md b/curriculum/challenges/english/10-coding-interview-prep/data-structures/implement-heap-sort-with-a-min-heap.english.md index cad247f43a..c29b879c58 100644 --- a/curriculum/challenges/english/10-coding-interview-prep/data-structures/implement-heap-sort-with-a-min-heap.english.md +++ b/curriculum/challenges/english/10-coding-interview-prep/data-structures/implement-heap-sort-with-a-min-heap.english.md @@ -43,10 +43,11 @@ tests: ```js // check if array is sorted -function isSorted(arr) { - var check = i => - i == arr.length - 1 ? true : arr[i] > arr[i + 1] ? false : check(i + 1); - return check(0); +function isSorted(a){ + for(let i = 0; i < a.length - 1; i++) + if(a[i] > a[i + 1]) + return false; + return true; } // generate a randomly filled array var array = new Array(); diff --git a/curriculum/challenges/english/10-coding-interview-prep/rosetta-code/sorting-algorithms-permutation-sort.english.md b/curriculum/challenges/english/10-coding-interview-prep/rosetta-code/sorting-algorithms-permutation-sort.english.md index edb7b7efce..f63b1d7546 100644 --- a/curriculum/challenges/english/10-coding-interview-prep/rosetta-code/sorting-algorithms-permutation-sort.english.md +++ b/curriculum/challenges/english/10-coding-interview-prep/rosetta-code/sorting-algorithms-permutation-sort.english.md @@ -91,8 +91,10 @@ function permutationSort(arr) { } } - function isSorted(a) { - for (var i = 1; i < a.length; i++) if (a[i - 1] > a[i]) return false; + function isSorted(a){ + for(let i = 0; i < a.length - 1; i++) + if(a[i] > a[i + 1]) + return false; return true; } diff --git a/curriculum/challenges/portuguese/08-coding-interview-prep/data-structures/implement-heap-sort-with-a-min-heap.portuguese.md b/curriculum/challenges/portuguese/08-coding-interview-prep/data-structures/implement-heap-sort-with-a-min-heap.portuguese.md index ba4cc31d1b..ad0bc75439 100644 --- a/curriculum/challenges/portuguese/08-coding-interview-prep/data-structures/implement-heap-sort-with-a-min-heap.portuguese.md +++ b/curriculum/challenges/portuguese/08-coding-interview-prep/data-structures/implement-heap-sort-with-a-min-heap.portuguese.md @@ -40,9 +40,11 @@ tests: ```js // check if array is sorted -function isSorted(arr) { - var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1); - return check(0); +function isSorted(a){ + for(let i = 0; i < a.length - 1; i++) + if(a[i] > a[i + 1]) + return false; + return true; } // generate a randomly filled array var array = new Array(); @@ -69,4 +71,5 @@ var MinHeap = function() { ```js // solution required ``` + diff --git a/curriculum/challenges/russian/08-coding-interview-prep/algorithms/implement-bubble-sort.russian.md b/curriculum/challenges/russian/08-coding-interview-prep/algorithms/implement-bubble-sort.russian.md index 111f53353e..ee2dae9a5f 100644 --- a/curriculum/challenges/russian/08-coding-interview-prep/algorithms/implement-bubble-sort.russian.md +++ b/curriculum/challenges/russian/08-coding-interview-prep/algorithms/implement-bubble-sort.russian.md @@ -29,7 +29,7 @@ tests: - text: bubbleSort returns an array that is unchanged except for order. testString: assert.sameMembers(bubbleSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]); - text: bubbleSort should not use the built-in .sort() method. - testString: assert.strictEqual(code.search(/\.sort\(/), -1); + testString: assert(isBuiltInSortUsed()); ``` @@ -57,11 +57,19 @@ bubbleSort([1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92])
```js -function isSorted(arr) { - var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1); - return check(0); -}; +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; + bubbleSort([0, 1]); + return !sortUsed; +} ```
diff --git a/curriculum/challenges/russian/08-coding-interview-prep/algorithms/implement-insertion-sort.russian.md b/curriculum/challenges/russian/08-coding-interview-prep/algorithms/implement-insertion-sort.russian.md index a8cac372af..0837fcccae 100644 --- a/curriculum/challenges/russian/08-coding-interview-prep/algorithms/implement-insertion-sort.russian.md +++ b/curriculum/challenges/russian/08-coding-interview-prep/algorithms/implement-insertion-sort.russian.md @@ -28,7 +28,7 @@ tests: - text: insertionSort returns an array that is unchanged except for order. testString: assert.sameMembers(insertionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]); - text: insertionSort should not use the built-in .sort() method. - testString: assert.strictEqual(code.search(/\.sort\(/), -1); + testString: assert(isBuiltInSortUsed()); ``` @@ -56,11 +56,19 @@ insertionSort([1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 9
```js -function isSorted(arr) { - var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1); - return check(0); -}; +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; + insertionSort([0, 1]); + return !sortUsed; +} ```
diff --git a/curriculum/challenges/russian/08-coding-interview-prep/algorithms/implement-merge-sort.russian.md b/curriculum/challenges/russian/08-coding-interview-prep/algorithms/implement-merge-sort.russian.md index 285d68318c..f528ae56e6 100644 --- a/curriculum/challenges/russian/08-coding-interview-prep/algorithms/implement-merge-sort.russian.md +++ b/curriculum/challenges/russian/08-coding-interview-prep/algorithms/implement-merge-sort.russian.md @@ -33,7 +33,7 @@ tests: - text: mergeSort returns an array that is unchanged except for order. testString: assert.sameMembers(mergeSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]); - text: mergeSort should not use the built-in .sort() method. - testString: assert.strictEqual(code.search(/\.sort\(/), -1); + testString: assert(isBuiltInSortUsed()); ``` @@ -62,11 +62,19 @@ mergeSort([1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]);
```js -function isSorted(arr) { - var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1); - return check(0); -}; +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; +} ```
diff --git a/curriculum/challenges/russian/08-coding-interview-prep/algorithms/implement-quick-sort.russian.md b/curriculum/challenges/russian/08-coding-interview-prep/algorithms/implement-quick-sort.russian.md index c4676ead97..7f762cb11f 100644 --- a/curriculum/challenges/russian/08-coding-interview-prep/algorithms/implement-quick-sort.russian.md +++ b/curriculum/challenges/russian/08-coding-interview-prep/algorithms/implement-quick-sort.russian.md @@ -28,7 +28,7 @@ tests: - text: quickSort returns an array that is unchanged except for order. testString: assert.sameMembers(quickSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]); - text: quickSort should not use the built-in .sort() method. - testString: assert.strictEqual(code.search(/\.sort\(/), -1); + testString: assert(isBuiltInSortUsed()); ``` @@ -58,11 +58,19 @@ function quickSort(array) {
```js -function isSorted(arr) { - var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1); - return check(0); -}; +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; + quickSort([0, 1]); + return !sortUsed; +} ```
diff --git a/curriculum/challenges/russian/08-coding-interview-prep/algorithms/implement-selection-sort.russian.md b/curriculum/challenges/russian/08-coding-interview-prep/algorithms/implement-selection-sort.russian.md index 78fa48f7eb..07877a922b 100644 --- a/curriculum/challenges/russian/08-coding-interview-prep/algorithms/implement-selection-sort.russian.md +++ b/curriculum/challenges/russian/08-coding-interview-prep/algorithms/implement-selection-sort.russian.md @@ -28,7 +28,7 @@ tests: - text: selectionSort returns an array that is unchanged except for order. testString: assert.sameMembers(selectionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]); - text: selectionSort should not use the built-in .sort() method. - testString: assert.strictEqual(code.search(/\.sort\(/), -1); + testString: assert(isBuiltInSortUsed()); ``` @@ -57,11 +57,19 @@ selectionSort([1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 9
```js -function isSorted(arr) { - var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1); - return check(0); -}; +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; + selectionSort([0, 1]); + return !sortUsed; +} ```
diff --git a/curriculum/challenges/russian/08-coding-interview-prep/data-structures/implement-heap-sort-with-a-min-heap.russian.md b/curriculum/challenges/russian/08-coding-interview-prep/data-structures/implement-heap-sort-with-a-min-heap.russian.md index 51a3733d06..4398a0b4ec 100644 --- a/curriculum/challenges/russian/08-coding-interview-prep/data-structures/implement-heap-sort-with-a-min-heap.russian.md +++ b/curriculum/challenges/russian/08-coding-interview-prep/data-structures/implement-heap-sort-with-a-min-heap.russian.md @@ -43,10 +43,11 @@ tests: ```js // check if array is sorted -function isSorted(arr) { - var check = i => - i == arr.length - 1 ? true : arr[i] > arr[i + 1] ? false : check(i + 1); - return check(0); +function isSorted(a){ + for(let i = 0; i < a.length - 1; i++) + if(a[i] > a[i + 1]) + return false; + return true; } // generate a randomly filled array var array = new Array(); diff --git a/curriculum/challenges/spanish/08-coding-interview-prep/data-structures/implement-heap-sort-with-a-min-heap.spanish.md b/curriculum/challenges/spanish/08-coding-interview-prep/data-structures/implement-heap-sort-with-a-min-heap.spanish.md index 73e6414fb1..c9e711b38f 100644 --- a/curriculum/challenges/spanish/08-coding-interview-prep/data-structures/implement-heap-sort-with-a-min-heap.spanish.md +++ b/curriculum/challenges/spanish/08-coding-interview-prep/data-structures/implement-heap-sort-with-a-min-heap.spanish.md @@ -40,9 +40,11 @@ tests: ```js // check if array is sorted -function isSorted(arr) { - var check = (i) => (i == arr.length - 1) ? true : (arr[i] > arr[i + 1]) ? false : check(i + 1); - return check(0); +function isSorted(a){ + for(let i = 0; i < a.length - 1; i++) + if(a[i] > a[i + 1]) + return false; + return true; } // generate a randomly filled array var array = new Array(); @@ -69,4 +71,5 @@ var MinHeap = function() { ```js // solution required ``` +