var var sequence -1 -1 -7 var negative var positive var indexNegative

 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 = 5;
var sequence = [-1, 4, -1, 6, -7];
var negative = [];
var positive = [];
var indexNegative = [];
var indexPositive = [];
for (var i = 0; i < sequence.length; i++){
if (sequence[i] < 0) {
negative.push(sequence[i]);
indexNegative.push(i);
}
else {
positive.push(sequence[i]);
indexPositive.push(i);
}
}
var sumNegative = 0;
var sumPositive = 0;
for (var i = 0; i < negative.length; i++){
sumNegative += negative[i];
}
for (var i = 0; i < positive.length; i++){
sumPositive += positive[i];
}
if (Math.abs(sumNegative) > Math.abs(sumPositive)){
console.log (negative.length);
console.log (indexNegative);
}
else if (Math.abs(sumNegative) < Math.abs(sumPositive)){
console.log (positive.length);
console.log (indexPositive);
}
else {
console.log("tie")
}