Ad
Arrays
Data Types
Algorithms
Logic
Data

Find positive and negative integer pair in the array.

There is only one pair in the array.

Think about the performance.

[1,2,3,-2,4,5,6] -> [-2, 2]

[1,5,7,8,-2,3,-7] -> [-7, 7]
function pairs(arr){
  let sorted = arr.sort();
  let length = arr.length;

  for (let i = 0; i < length; i++) {
    if (sorted.includes(arr[i] * -1)) {
      return [sorted[i], sorted[i] * -1];
    }
  }
}