Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Array.prototype.last = function(propertySelector = obj => obj) {
const filtered = this.filter(propertySelector);
return filtered[filtered.length - 1];
};
function lastDemo(orders) {
const lastOrderAfterMarch = orders.last(order => order.orderDate >= march);
printHeaderFooter(
"Last order after March",
() => printOrder(lastOrderAfterMarch, indentBy),
indentBy
);
const lastOrderAfterSeptember =
orders.last(order => order.orderDate >= september) || null;
printHeaderFooter(
"Last or Default order after September",
() => printOrder(lastOrderAfterSeptember, indentBy),
indentBy
);
}
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.