After running the code snippet provided, I noticed that it outputs "first" instead of "second". Can you help me verify my logic here? I first calculate both averages and then compare them to return the greater one. Do you see any issues with this approach?
var first = ([100, 80], [100, 100]);
function compare(a, b) {
sum = 0;
for(var i = 0; i < a.length; i++) {
sum += first[i];
avg1 = (sum/a.length);
}
sum2 = 0;
for(i = 0; i < b.length; i++) {
sum2 += first[i];
avg2 = (sum2/b.length);
}
if (avg1 > avg2); {
return ("first");
}
if (false) {
return ("second");
}
}