UNPKG

@safs.io/match

Version:

Gale/Shapely deferred acceptance algorithm

2 lines (1 loc) 396 B
function f(e){return e.reduce((r,t)=>(t.acceptedCounterparts.forEach(h=>{r.push({left:h,right:t})}),r),[])}function c({leftEls:e,rightEls:r}){for(;e.length;){let t=e.shift();if(typeof t=="undefined")break;let{rankedCounterparts:h}=t;for(;h.length;){let n=h.shift();if(n==null?void 0:n.willAcceptCounterpart(t)){let i=n.acceptCounterpart(t);i&&e.unshift(i);break}}}return f(r)}export{c as match};