Created
March 31, 2018 18:19
-
-
Save dance2die/0013a7255e993ac11914e663799fd8c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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