Last active
May 13, 2020 15:52
-
-
Save jamesmcallister/7a454eed1f2d33c1a8de14e250462147 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
function avergePrice() { | |
var values = [ | |
...new Set( | |
$$(".POSITIVE") | |
.map((i) => i.innerHTML.replace("£", "")) | |
.map(i => parseInt(i)) | |
.filter(i => !Number.isNaN(i)) | |
.sort((a, b) => a - b) | |
) | |
]; | |
const middleNumbers = values.length / 4; | |
const firstHalf = values.slice(middleNumbers, values.length); | |
const lastHalf = firstHalf.reverse().slice(middleNumbers, firstHalf.length).reverse(); | |
let sum = lastHalf.reduce((previous, current) => (current += previous)); | |
let avg = (sum / lastHalf.length).toFixed(2); | |
console.log({min: lastHalf[0], avg, max: lastHalf[lastHalf.length -1]}); | |
} | |
avergePrice() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment