Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Array.prototype.average = function(propertySelector = obj => obj) {
const intialValue = 0;
return (
this.reduce((sum, obj) => sum + propertySelector(obj), intialValue) /
this.length
);
};
function averageDemo(orders) {
var averageQuantity = orders.average(order => order.quantity);
var totalQuantities = orders.sum(order => order.quantity);
var count = orders.length;
WriteLine(
`Average Quantity: ${totalQuantities} / ${count} = ${averageQuantity}`
);
}
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.