var var sequence -8 -7 var min var max var min2 var max2 for sequence

 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
var x = 6;
var sequence = [1, -8, 4, 5, 2, -7];
var min = 0;
var max = 0;
var min2 = 0;
var max2 = 0;
for (i = 0; i < sequence.length; i++){
if (sequence[i] < min) {
min = sequence [i];
}
if (sequence[i] > max) {
max = sequence [i];
}
}
for (i = 0; i < sequence.length; i++){
if (sequence[i] < min2 && sequence[i] != min) {
min2 = sequence [i];
}
if (sequence[i] > max2 && sequence[i] != max) {
max2 = sequence [i];
}
}
var sumMax = Math.abs(max + max2);
var sumMin = Math.abs(min + min2);
if (sumMax > sumMin) {
console.log (max, max2)
}
else{
console.log (min, min2);
}