Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Array.prototype.except = function(other, idSelector = obj => obj) {
const otherSet = new Set([...other.map(idSelector)]);
// Reference: http://2ality.com/2015/01/es6-set-operations.html
const difference = new Set(this.filter(object => !otherSet.has(idSelector(object))));
return [...difference];
};
function exceptDemo(ordersOnHold, domesticOrders, internationalOrders) {
const orderIdSelector = order => order.id;
const allOrders = domesticOrders.union(internationalOrders);
const allOrdersNotOnHold = allOrders.except(ordersOnHold, orderIdSelector);
printOrders(allOrdersNotOnHold);
}
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.