Created
May 14, 2018 17:35
-
-
Save ff8c00/4c323e994a35ea7d7d0d31127799204f to your computer and use it in GitHub Desktop.
Reddit Daily Programmer 360 Intermediate
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
<html> | |
<head> | |
<script src="GreatCircle.js"> | |
</script> | |
<script> | |
function open(url, callback) { | |
var xhttp; | |
xhttp = new XMLHttpRequest(); | |
xhttp.onreadystatechange = function() { | |
if (this.readyState == 4 && this.status == 200) { | |
callback(this.responseText); | |
} | |
}; | |
xhttp.open("GET", url, true); | |
xhttp.send(); | |
} | |
function run() { | |
open("https://opensky-network.org/api/states/all", function(response) { | |
var point = [48.8584, 2.2945]; | |
var states = JSON.parse(response).states; | |
var items = states.map(function(item) { | |
return [ | |
item[8], | |
GreatCircle.distance(this[0], this[1], item[6], item[5]), | |
item[1], | |
item[6], | |
item[5], | |
item[7], | |
item[2], | |
item[0] | |
]; | |
}, point); | |
items.sort(function(a, b) { | |
return !a[0] ? a[1] - b[1] : 1; | |
}); | |
var item = items[0]; | |
document.write([ | |
item[1].toFixed(2), | |
item[2] == null ? "" : item[2].trim(), | |
item[3].toFixed(4) + ", " + item[4].toFixed(4), | |
item[5].toFixed(2), | |
item[6] == null ? "" : item[6].trim(), | |
item[7] == null ? "" : item[7].trim(), | |
].join("<br>")); | |
}); | |
} | |
</script> | |
</head> | |
<body onload="run()"> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment