Skip to content

Instantly share code, notes, and snippets.

@F0urO4
Last active January 12, 2023 04:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save F0urO4/cfde1fed4d43affdc175bf56ee32a87d to your computer and use it in GitHub Desktop.
Save F0urO4/cfde1fed4d43affdc175bf56ee32a87d to your computer and use it in GitHub Desktop.
average ebay price
var getItems = () => Array.from(document.querySelectorAll('.srp-river-results .s-item__price'));
var getPrices = () => getItems().map((item) => parseFloat((item.textContent.match(/\d+.\d+/)[0])));
var sum = () => getPrices().reduce((a, b) => b + a, 0 );
var getAvg = () => sum() / getPrices().length;
console.log(getAvg().toFixed(2));
@aalvarado
Copy link

var digits = new RegExp('\d+.\d+')
var getItems = () => Array.from(document.querySelectorAll('.srp-river-results .s-item__price'))

var getPrices = () => getItems().map((item) => parseFloat(item.innerText.match(digits)[0]))

var sum = () => getPrices().reduce((a, b) => b + a, 0 )

var getAvg = () => sum() / getPrices().length

console.log(getAvg().toFixed(2))

@F0urO4
Copy link
Author

F0urO4 commented Jan 9, 2023

I used aalvarado's code but it was giving me an error. I've updated it now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment