FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaScriptExercises/sort2.js at master · marshmeryl/JavaScriptExercises · GitHub
marshmeryl
/
JavaScriptExercises
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
JavaScriptExercises
/
sort2.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
37 lines (32 loc) · 746 Bytes
Breadcrumbs
JavaScriptExercises
/
sort2.js
Copy path
File metadata and controls
37 lines (32 loc) · 746 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
31
32
33
34
35
36
37
function
sort2
(
numArray
)
{
var
copiedArray
=
numArray
.
slice
(
)
;
var
result
=
[
]
;
if
(
copiedArray
.
length
===
0
)
{
return
[
]
;
}
var
min
;
var
index
;
while
(
copiedArray
.
length
>
0
)
{
min
=
Math
.
min
.
apply
(
Math
,
copiedArray
)
;
index
=
copiedArray
.
indexOf
(
min
)
;
copiedArray
.
splice
(
index
,
1
)
;
result
.
push
(
min
)
;
}
return
result
;
}
var
testCase
=
[
[
1
,
3
,
-
2
,
5
,
100
,
-
2
]
,
[
6
,
5
,
4
,
3
,
1
,
0
,
-
10
,
-
21
]
,
[
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
]
,
[
1000
,
1
,
2000
,
2
,
3000
,
3
]
,
[
9999
,
9
,
8888
,
8
,
7777
,
7
]
,
[
]
,
[
1
,
2
]
,
[
1
,
0
]
,
[
1
,
1
,
1
,
1
,
1
,
10
,
1
,
1
,
1
,
1
]
,
[
1
,
1
,
1
,
1
,
1
,
-
10
,
1
,
1
,
1
,
1
]
]
;
for
(
var
i
=
0
;
i
<
testCase
.
length
;
i
++
)
{
console
.
log
(
"Before sort: "
+
testCase
[
i
]
)
;
console
.
log
(
"After sort: "
+
sort2
(
testCase
[
i
]
)
+
"\n"
)
;
}
Back
|
FazBrowse Home
|
New Git URL