FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
javascript/algorithms/sorting/selectionSort.js at master · AllAlgorithms/javascript · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
This repository was archived by the owner on Sep 7, 2025. It is now read-only.
AllAlgorithms
/
javascript
Public archive
Notifications
You must be signed in to change notification settings
Fork
43
Star
89
Code
Issues
0
Pull requests
0
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
javascript
/
algorithms
/
sorting
/
selectionSort.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
28 lines (25 loc) · 560 Bytes
Breadcrumbs
javascript
/
algorithms
/
sorting
/
selectionSort.js
Copy path
File metadata and controls
28 lines (25 loc) · 560 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
// JavaScript implementation of selection sort
//
// Author: Niezwan Abdul Wahid
function
selectionSort
(
arr
)
{
let
min
,
temp
;
let
len
=
arr
.
length
;
for
(
let
i
=
0
;
i
<
len
;
i
++
)
{
min
=
i
;
for
(
let
j
=
i
+
1
;
j
<
len
;
j
++
)
{
if
(
arr
[
j
]
<
arr
[
min
]
)
{
min
=
j
;
}
}
temp
=
arr
[
i
]
;
arr
[
i
]
=
arr
[
min
]
;
arr
[
min
]
=
temp
;
}
return
arr
;
}
// Test
let
arr
=
[
-
8
,
46
,
24
,
33
,
10
,
2
,
81
,
50
]
;
console
.
log
(
'Unsorted array '
)
;
console
.
log
(
arr
.
slice
(
)
)
;
console
.
log
(
'Sorted array '
)
;
console
.
log
(
selectionSort
(
arr
.
slice
(
)
)
)
;
Back
|
FazBrowse Home
|
New Git URL