Skip to content

Instantly share code, notes, and snippets.

@jamesmcallister
Last active May 13, 2020 15:52
Show Gist options
  • Save jamesmcallister/7a454eed1f2d33c1a8de14e250462147 to your computer and use it in GitHub Desktop.
Save jamesmcallister/7a454eed1f2d33c1a8de14e250462147 to your computer and use it in GitHub Desktop.
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