GeezerVison is showing github.com — merge: Add Description and Optamization (#852) · Algorithms-Learn/JavaScript@cc34088
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: Sorts/QuickSort.js +10-9Lines changed: 10 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | /** |
2 | | -* Quick sort is a comparison sorting algorithm that uses a divide and conquer strategy. |
3 | | -* |
4 | | -* For more information see here: https://en.wikipedia.org/wiki/Quicksort |
5 | | -*/ |
6 | | -export function quickSort (items) { |
| 2 | + * @function QuickSort |
| 3 | + * @description Quick sort is a comparison sorting algorithm that uses a divide and conquer strategy. |
| 4 | + * @param {Integer[]} items - Array of integers |
| 5 | + * @return {Integer[]} - Sorted array. |
| 6 | + * @see [QuickSort](https://en.wikipedia.org/wiki/Quicksort) |
| 7 | + */ |
| 8 | +function quickSort (items) { |
7 | 9 | const length = items.length |
8 | 10 |
|
9 | 11 | if (length <= 1) { |
@@ -21,9 +23,8 @@ export function quickSort (items) { |
21 | 23 | } |
22 | 24 | } |
23 | 25 |
|
24 | | - let sorted = quickSort(LESSER) |
25 | | - sorted.push(PIVOT) |
26 | | - sorted = sorted.concat(quickSort(GREATER)) |
27 | | - |
| 26 | + const sorted = [...quickSort(LESSER), PIVOT, ...quickSort(GREATER)] |
28 | 27 | return sorted |
29 | 28 | } |
| 29 | + |
| 30 | +export { quickSort } |