FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaScriptAlgorithm/Sorts/QuickSort.js at master · RabibHossain/JavaScriptAlgorithm · GitHub
RabibHossain
/
JavaScriptAlgorithm
Public
forked from
TheAlgorithms/JavaScript
Notifications
You must be signed in to change notification settings
Fork
1
Star
1
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaScriptAlgorithm
/
Sorts
/
QuickSort.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
30 lines (26 loc) · 706 Bytes
Breadcrumbs
JavaScriptAlgorithm
/
Sorts
/
QuickSort.js
Copy path
File metadata and controls
30 lines (26 loc) · 706 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
*
@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
)
{
return
items
}
const
PIVOT
=
items
[
0
]
const
GREATER
=
[
]
const
LESSER
=
[
]
for
(
let
i
=
1
;
i
<
length
;
i
++
)
{
if
(
items
[
i
]
>
PIVOT
)
{
GREATER
.
push
(
items
[
i
]
)
}
else
{
LESSER
.
push
(
items
[
i
]
)
}
}
const
sorted
=
[
...
quickSort
(
LESSER
)
,
PIVOT
,
...
quickSort
(
GREATER
)
]
return
sorted
}
export
{
quickSort
}
Back
|
FazBrowse Home
|
New Git URL