Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Array.prototype.intersect = function(other, idSelector = obj => obj) {
const otherSet = new Set([]);
// Reference:
const intersection = new Set(this.filter(object => otherSet.has(idSelector(object))));
return [...intersection];
function intersectDemo(ordersOnHold, domesticOrders, internationalOrders) {
const orderIdSelector = order =>;
const usOrdersOnHold = ordersOnHold.intersect(domesticOrders, orderIdSelector);
const internationalOrdersOnHold = ordersOnHold.intersect(internationalOrders, orderIdSelector);
const indentBy = 4;
const dividerCharacter = "*";
printHeaderFooter("US Orders on hold", () => printOrders(usOrdersOnHold, indentBy), indentBy, dividerCharacter);
printHeaderFooter("International Orders on hold", () => printOrders(internationalOrdersOnHold, indentBy), indentBy, dividerCharacter);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.