Created
June 23, 2019 01:46
-
-
Save beganovich/ef33e3dc87641f62a8548c687305d829 to your computer and use it in GitHub Desktop.
Javascript: Highest, lowes and average in array of objects
This file contains hidden or 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
const orderBy = (order, array) => Math[order](...array.map(i => i.number)) | |
const getAvg = (array) => array.reduce((previous,next) => previous + next.number, 0) / array.length | |
let values = [ | |
{ name: "Benjamin", number: 1 }, | |
{ name: "Someone Else", number: 3 } | |
] | |
console.log(`Highest: ${orderBy('max', values)}`) | |
console.log(`Lowest: ${orderBy('min', values)}`) | |
console.log(`Average: ${getAvg(values)}`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment