FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
javascript-algorithms/SelectionSort.js at main · devcer/javascript-algorithms · GitHub
devcer
/
javascript-algorithms
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
javascript-algorithms
/
SelectionSort.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
21 lines (21 loc) · 491 Bytes
Breadcrumbs
javascript-algorithms
/
SelectionSort.js
Copy path
File metadata and controls
21 lines (21 loc) · 491 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
function
sort
(
arr
)
{
for
(
let
i
=
0
;
i
<
arr
.
length
;
i
++
)
{
let
elem
=
arr
[
i
]
,
index
=
i
;
for
(
let
j
=
i
+
1
;
j
<
arr
.
length
;
j
++
)
{
if
(
arr
[
j
]
<
elem
)
{
elem
=
arr
[
j
]
;
index
=
j
;
}
}
if
(
elem
!==
arr
[
i
]
)
{
arr
[
index
]
=
arr
[
i
]
;
arr
[
i
]
=
elem
;
}
}
return
arr
;
}
// Selection Sort Time complexity- Ω(n) θ(n^2) O(n^2)
// space - O(1)
console
.
log
(
sort
(
[
14
,
33
,
27
,
10
,
35
,
19
,
42
,
44
]
)
)
;
console
.
log
(
sort
(
[
3
,
2
,
1
,
4
]
)
)
;
Back
|
FazBrowse Home
|
New Git URL