fix(learn): Consolidated comments for Coding Interview Prep challenges - part 2 of 2 (#39576)
* fix: consolidate comments for use with the translation dictionary * fix: added blank line between comments Co-authored-by: Tom <20648924+moT01@users.noreply.github.com> * fix: removed unneeded comment Co-authored-by: Tom <20648924+moT01@users.noreply.github.com>
This commit is contained in:
@ -44,9 +44,9 @@ tests:
|
||||
|
||||
```js
|
||||
function bubbleSort(array) {
|
||||
// change code below this line
|
||||
// Only change code below this line
|
||||
return array;
|
||||
// change code above this line
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
bubbleSort([1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]);
|
||||
|
@ -42,9 +42,9 @@ tests:
|
||||
|
||||
```js
|
||||
function insertionSort(array) {
|
||||
// change code below this line
|
||||
// Only change code below this line
|
||||
return array;
|
||||
// change code above this line
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
insertionSort([1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]);
|
||||
|
@ -46,10 +46,9 @@ tests:
|
||||
|
||||
```js
|
||||
function mergeSort(array) {
|
||||
// change code below this line
|
||||
|
||||
// change code above this line
|
||||
// Only change code below this line
|
||||
return array;
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
mergeSort([1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]);
|
||||
|
@ -10,7 +10,6 @@ forumTopicId: 301615
|
||||
Here we will move on to an intermediate sorting algorithm: quick sort. Quick sort is an efficient, recursive divide-and-conquer approach to sorting an array. In this method, a pivot value is chosen in the original array. The array is then partitioned into two subarrays of values less than and greater than the pivot value. We then combine the result of recursively calling the quick sort algorithm on both sub-arrays. This continues until the base case of an empty or single-item array is reached, which we return. The unwinding of the recursive calls return us the sorted array.
|
||||
Quick sort is a very efficient sorting method, providing <i>O(nlog(n))</i> performance on average. It is also relatively easy to implement. These attributes make it a popular and useful sorting method.
|
||||
<strong>Instructions:</strong> Write a function <code>quickSort</code> which takes an array of integers as input and returns an array of these integers in sorted order from least to greatest. While the choice of the pivot value is important, any pivot will do for our purposes here. For simplicity, the first or last element could be used.
|
||||
<strong>Note:</strong><br>We are calling this function from behind the scenes; the test array we are using is commented out in the editor. Try logging <code>array</code> to see your sorting algorithm in action!
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
@ -27,7 +26,7 @@ tests:
|
||||
testString: assert(typeof quickSort == 'function');
|
||||
- text: <code>quickSort</code> should return a sorted array (least to greatest).
|
||||
testString: assert(isSorted(quickSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])));
|
||||
- text: <code>quickSort</code> should return an array that is unchanged except for order.
|
||||
- text: <code>quickSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])</code> 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: <code>quickSort</code> should not use the built-in <code>.sort()</code> method.
|
||||
testString: assert(isBuiltInSortUsed());
|
||||
@ -43,14 +42,10 @@ tests:
|
||||
|
||||
```js
|
||||
function quickSort(array) {
|
||||
// change code below this line
|
||||
|
||||
// change code above this line
|
||||
// Only change code below this line
|
||||
return array;
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
// test array:
|
||||
// [1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]
|
||||
```
|
||||
|
||||
</div>
|
||||
@ -106,9 +101,6 @@ function quickSort(array) {
|
||||
return [...quickSort(lesser), ...equal, ...quickSort(greater)];
|
||||
}
|
||||
}
|
||||
|
||||
// test array:
|
||||
// [1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]
|
||||
```
|
||||
|
||||
</section>
|
||||
|
@ -42,9 +42,9 @@ tests:
|
||||
|
||||
```js
|
||||
function selectionSort(array) {
|
||||
// change code below this line
|
||||
// Only change code below this line
|
||||
return array;
|
||||
// change code above this line
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
|
||||
|
@ -44,7 +44,6 @@ tests:
|
||||
|
||||
```js
|
||||
function updateInventory(arr1, arr2) {
|
||||
// All inventory must be accounted for or you're fired!
|
||||
return arr1;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user