Skip to content

Add Description and Optamization #852

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions Sorts/QuickSort.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/**
* Quick sort is a comparison sorting algorithm that uses a divide and conquer strategy.
*
* For more information see here: https://en.wikipedia.org/wiki/Quicksort
*/
export function quickSort (items) {
* @function QuickSort
* @description Quick sort is a comparison sorting algorithm that uses a divide and conquer strategy.
* @param {Integer[]} items - Array of integers
* @return {Integer[]} - Sorted array.
* @see [QuickSort](https://en.wikipedia.org/wiki/Quicksort)
*/
function quickSort (items) {
const length = items.length

if (length <= 1) {
Expand All @@ -21,9 +23,8 @@ export function quickSort (items) {
}
}

let sorted = quickSort(LESSER)
sorted.push(PIVOT)
sorted = sorted.concat(quickSort(GREATER))

const sorted = [...quickSort(LESSER), PIVOT, ...quickSort(GREATER)]
return sorted
}

export { quickSort }