May 11th, 2024
What's missing in this code?
// Check if sum of diff between unique positives
// is more than sum of negatives
// sum of pos pair diff: (1 - 5) + (5 - 7) = -4 + -2 = -6
// sum of neg: -2 - 3 = -5
// isPositiveDominant([1, -2, 5, -3, 7]); // true (-6 < -5)
// isPositiveDominant([1, 2, 3, -4, -5]); // true (-2 > -9)
// isPositiveDominant([-7, 5, 3, 2, 4]); // true (1 > -7)
function isPositiveDominant(arr)
const positives =
;
let positiveDiffSum = 0;
for (let i = 0; i < positives.length - 1; i++)
positiveDiffSum +=
;
}
const negativeSum = arr
.filter((x) => x < 0)
;
return positiveDiffSum > negativeSum;
}
Type or select from these options