Created
August 21, 2018 08:21
-
-
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
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
// 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)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
List of all airliners