Skip to content

Instantly share code, notes, and snippets.

@dance2die
Created March 31, 2018 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dance2die/a33e3a0fbad62840fdba9ad70260aef1 to your computer and use it in GitHub Desktop.
Save dance2die/a33e3a0fbad62840fdba9ad70260aef1 to your computer and use it in GitHub Desktop.
Array.prototype.count = function(predicate = obj => true) {
return this.filter(predicate).length;
};
function countDemo(orders) {
const march = new Date(2018, 3, 1);
const ordersOnAndAfterMarch = orders.filter(
order => order.orderDate >= march
);
printOrders(ordersOnAndAfterMarch, (indentBy = 4));
const orderCountPlacedOnAndAfterMarch = orders.count(
order => order.orderDate >= march
);
WriteLine(
`Total Orders Placed On and After March: ${orderCountPlacedOnAndAfterMarch}`
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment