-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPeaks.js
More file actions
44 lines (34 loc) · 967 Bytes
/
Copy pathPeaks.js
File metadata and controls
44 lines (34 loc) · 967 Bytes
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
//Score: 100%
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
if(A.length < 3)
return 0;
for(var e = 1; e <= A.length; e ++){
if(A.length%e != 0)
continue;
var peaksLen = 0;
var countBlocks = 0;
for(var i = 1; i < A.length - 1 ; i++){
if(A[i-1] < A[i] && A[i] > A[i+1]){
peaksLen++;
}
if((i+1)%e == 0){
if(peaksLen>0){
countBlocks++;
peaksLen = 0;
}
else{
peaksLen = 0;
countBlocks = 0;
break;
}
}
}
if(peaksLen > 0){
return countBlocks+1;
}
}
return 0;
}