threeSum = function (nums) {
  const array = nums.reduce((acc, n, i) => { // O(n^2)
    if (i > nums.length - 2) return acc;
    const partial = twoSum(nums, -n, i + 1);
    const res = partial.map((p) => [n, ...p]);
    // console.log({i, n, partial, res, acc})
    return acc.concat(res);
  }, []);

  // remove dups
  const set = array.reduce((acc, n) => {
    const str = n.sort((a, b) => a - b).toString();
    return acc.add(str);
  }, new Set());

  // convert to array of nums
  return [...set].map((a) => a.split(',').map((n) => +n));
}
@param {number[]} nums
@return {number[][]}

@runtime O(n^2)
@space O(n)