Skip to content

Instantly share code, notes, and snippets.

@itainathaniel
Created August 21, 2018 08:21
Show Gist options
  • Save itainathaniel/5aad544edc997bb46df11d8c717d90f0 to your computer and use it in GitHub Desktop.
Save itainathaniel/5aad544edc997bb46df11d8c717d90f0 to your computer and use it in GitHub Desktop.
JS calculator of fleet size & age. You need to be a member, though
// go to https://www.flightradar24.com/data/airlines/<airliner>/fleet and run on console
const planes = [];
const tables = document.querySelectorAll('.table-condensed');
tables.forEach(table => {
let tbody = table.querySelector('tbody');
let trs = tbody.querySelectorAll('tr');
trs.forEach(tr => {
let age = parseInt(tr.querySelector('td:last-child').innerText, 10);
if (isNaN(age)) {
age = 0;
}
planes.push(age);
});
});
var average = arr => arr.reduce( ( p, c ) => p + c, 0 ) / arr.length;
console.log('fleet size: ', planes.length);
console.log('fleet average age: ', average(planes));
@itainathaniel
Copy link
Author

itainathaniel commented Aug 21, 2018

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