const sumZeroPair = (arr) => { let left = 0, // -4 right = arr.length - 1; // 4 while (left < right) { let sum = arr[left] + arr[right]; // 0 if (sum === 0) return [arr[left], arr[right]]; // true else if (sum > 0) right--; else left++; } }; const res = sumZeroPair([-5, -4, -3, -2, 0, 2, 4, 6, 8]); console.log(res);