FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JS-code/codility/src/script6.js at master · Vitaminvp/JS-code · GitHub
Vitaminvp
/
JS-code
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
2
Code
Issues
0
Pull requests
30
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JS-code
/
codility
/
src
/
script6.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
34 lines (31 loc) · 1.11 KB
Breadcrumbs
JS-code
/
codility
/
src
/
script6.js
Copy path
File metadata and controls
34 lines (31 loc) · 1.11 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
function
solution
(
arr
)
{
let
max
=
0
;
for
(
let
i
=
0
;
i
<
arr
.
length
;
i
++
)
{
let
j
=
i
;
let
numbers
=
new
Set
;
while
(
j
<
arr
.
length
&&
numbers
.
size
<=
2
)
numbers
.
add
(
arr
[
j
++
]
)
;
// console.log("number", numbers);
max
=
Math
.
max
(
max
,
j
-
i
-
(
numbers
.
size
>
2
?
1
:
0
)
)
;
// console.log("max", max);
}
return
max
;
}
// function solution(arr) {
// let max=0;
// for (let i=0; i<arr.length; i++){
// let j=i+1;
// let numbers = new Set;
// numbers.add(arr[i]);
// while( j < arr.length && numbers.size < 2 ) numbers.add(arr[j++]);
// console.log("number", numbers);
// max = Math.max(max, j-i+1);
// console.log("max", max);
//
// }
// return max;
// }
console
.
log
(
"solution"
,
solution
(
[
5
,
4
,
4
,
5
,
0
,
12
]
)
)
;
console
.
log
(
"solution"
,
solution
(
[
5
,
4
,
4
,
5
,
0
,
3
,
1
]
)
)
;
console
.
log
(
"solution"
,
solution
(
[
1
,
2
,
4
,
1
,
2
,
5
,
4
,
4
,
5
,
0
,
3
,
1
]
)
)
;
console
.
log
(
"[5, 4, 4, 5, 0, 3, 1].map(String)"
,
[
5
,
4
,
4
,
5
,
0
,
3
,
1
]
.
map
(
String
)
)
;
console
.
log
(
"[\"1\", \"2\", \"3\", \"4\"].map(Number)"
,
[
"1"
,
"2"
,
"3"
,
"4"
]
.
map
(
Number
)
)
;
Back
|
FazBrowse Home
|
New Git URL