FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithm-by-javascript/bak/array/56.js at master · wenzi0github/algorithm-by-javascript · GitHub
wenzi0github
/
algorithm-by-javascript
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
2
Code
Issues
1
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithm-by-javascript
/
bak
/
array
/
56.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
55 lines (54 loc) · 1.16 KB
Breadcrumbs
algorithm-by-javascript
/
bak
/
array
/
56.js
Copy path
File metadata and controls
55 lines (54 loc) · 1.16 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
function
merge
(
intervals
)
{
const
len
=
intervals
.
length
;
if
(
len
<=
1
)
{
return
intervals
;
}
let
result
=
[
intervals
[
0
]
]
;
for
(
let
i
=
1
;
i
<
len
;
i
++
)
{
const
[
istart
,
iend
]
=
intervals
[
i
]
;
const
resultLen
=
result
.
length
;
let
j
=
0
;
while
(
j
<
resultLen
)
{
let
[
start
,
end
]
=
result
[
j
]
;
if
(
(
istart
>=
start
&&
istart
<=
end
)
||
(
iend
>=
start
&&
iend
<=
end
)
||
(
start
>=
istart
&&
start
<=
iend
)
||
(
end
>=
istart
&&
end
<=
iend
)
)
{
start
=
Math
.
min
(
istart
,
start
)
;
end
=
Math
.
max
(
iend
,
end
)
;
result
[
j
]
=
[
start
,
end
]
;
break
;
}
j
++
;
}
if
(
j
>=
resultLen
)
{
result
.
push
(
[
istart
,
iend
]
)
;
}
}
return
result
;
}
console
.
log
(
merge
(
[
[
1
,
3
]
,
[
2
,
6
]
,
[
8
,
10
]
,
[
15
,
18
]
,
]
)
)
;
console
.
log
(
merge
(
[
[
1
,
4
]
,
[
4
,
5
]
,
]
)
)
;
console
.
log
(
merge
(
[
[
2
,
3
]
,
[
4
,
5
]
,
[
6
,
7
]
,
[
8
,
9
]
,
[
1
,
10
]
,
]
)
)
;
Back
|
FazBrowse Home
|
New Git URL