Q:

How to get unique sub arrays within an array in Javascript

So I have this function that determines whether 2 the sum of two numbers within an array are equal to a given target number.
The function gives out all the possible combinations of achieving the target number but I only want unique sub-arrays.
let targetNum = 10
const array = [5,2,3,3,7,1,5]
const sumTwoNums = (array,num) => {
  let newArray = [];
  for (var i=0;i<array.length;i++) {
    for (var j=0;j<array.length;j++) {
      if(i!==j && array[i]+array[j]===num){
        newArray.push([array[i],array[j]]);
      }
    }
  }
  return newArray
}// returns [[5,5],[3,7],[3,7],[7,3],[7,3],[5,5]]

What can I do to solve this issue?

A:

I think this answer solves your problem . 
function allPairs(ints, s) {
    var hash = Object.create(null),
        i,
        value,
        pairs = [];

    for (i = 0; i < ints.length; i++) {
        value = ints[i];
        if (hash[value]) pairs.push([s - value, value]);
        hash[s - value] = true;
    }
    return pairs;
}

console.log(allPairs([7, 2, 5, 8, 4, 3], 7));

