JS array group items by comparing items : i have array like this

    var oArr = [
      { id: "d1", x: 2, y: 2 },
      { id: "d1", x: 3, y: 3 },
      { id: "d1", x: 5, y: 3 },
      { id: "d1", x: 5, y: 7 },
      { id: "d1", x: 3, y: 6 },

    ];

i want to subtract all items' "y" properties to each other and test if it is smaller then the given threshold value.And finally group items in nested-arrays...

    var threshold =2;

So my expected output is

    var result= [
     [ { id: "d1", x: 2, y: 2 },{ id: "d1", x: 3, y: 3 }, { id: "d1", x: 5, y: 3 }],
      [ { id: "d1", x: 5, y: 7 }, { id: "d1", x: 3, y: 6 }]
    
    ];

in the second part of the problem , i want to find minimum y value of each item and reduce array to 2 elements. 

My second expected output

    var result= [
      { id: "d1", x: 2, y: 2 },
       { id: "d1", x: 3, y: 6 }]
    
    ];
Second part is reather simple(reduce/filter and Math.min).My main problem is first part.
Any suggestion or advice would be appriciated
