Skip to content

Instantly share code, notes, and snippets.

@rimian
Last active January 9, 2019 09:53
Show Gist options
  • Save rimian/b4545cd355931f959bc2475ee4e0b54a to your computer and use it in GitHub Desktop.
Save rimian/b4545cd355931f959bc2475ee4e0b54a to your computer and use it in GitHub Desktop.
get car details
const sum = (arr) => arr.reduce((a, b) => a + b);
const average = (arr) => sum(arr)/arr.length;
kms = $(".feature-title:contains('Odometer')").next('div').text().split(' km').filter(k => k.length).map(k => parseInt(k.replace(',', '')));
prices = $('.ad-price .price').text().split('$').filter(p => p.length).map(p => parseInt(p.replace(',', '')));
avKms = average(kms);
avPrice = average(prices);
pricePerKm = avPrice/avKms;
console.log('Average Kms: ' + avKms);
console.log('Average price: $' + avPrice);
console.log('price/km: ' + pricePerKm);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment