Skip to content

Instantly share code, notes, and snippets.

@rosalesnikho
Last active August 20, 2019 15:46
Show Gist options
  • Save rosalesnikho/bc6e2d535ee36a86336d3ee5e71ee657 to your computer and use it in GitHub Desktop.
Save rosalesnikho/bc6e2d535ee36a86336d3ee5e71ee657 to your computer and use it in GitHub Desktop.
// This is the solution I found for the streak of launches
const baseLaunchURL = "https://api.spacexdata.com/v3/launches/";
// Schedule API
// Get All Launch Data
const getAllLaunchInformation = () => {
return fetch(baseLaunchURL)
.then(response => response.json())
}
// Data
getAllLaunchInformation().then((launchData) => {
let successfullAttempts;
let failedAttempts;
launchData.map((launch) => {
if(launch.launch_success === true ) {
successfullAttempts = launch.launch_success;
return console.log(successfullAttempts + " - Success Streak")
} else if (launch.launch_success === false) {
failedAttempts = launch.launch_success;
return console.log(failedAttempts);
}
})
});
// This counts the number of 'true' from the array and ends at the next false it sees
// The first 3 were failed launches, then they had a streak of 20, then failed 1, had a streak of 9, failed one again,
// then had another streak of 49 successful launches.
// This outputs
(20) true - Success Streak
(9) true - Success Streak
(49) true - Success Streak
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment