Skip to content

Instantly share code, notes, and snippets.

@johnny-y-wang
Created March 6, 2019 07:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnny-y-wang/2a8a6a0c77d388bbe8b6ac2c467c1ff4 to your computer and use it in GitHub Desktop.
Save johnny-y-wang/2a8a6a0c77d388bbe8b6ac2c467c1ff4 to your computer and use it in GitHub Desktop.
Calculate total cost of the most recent 50 Uber trips
(async function () {
(fetch("https://riders.uber.com/api/getTripsForClient", {"credentials":"include","headers":{"accept":"*/*","accept-language":"en-US,en;q=0.9","content-type":"application/json","x-csrf-token":"*INSERT YOUR TOKEN HERE*"},"referrer":"https://riders.uber.com/trips?offset=0","referrerPolicy":"no-referrer-when-downgrade","body":"{\"limit\":50,\"offset\":\"0\",\"range\":{\"fromTime\":null,\"toTime\":null}}","method":"POST","mode":"cors"})).then(function(response) {
return response.json();
}).then(function(data) {
const trips = data.data.trips.trips;
const totalCosts = trips.reduce((acc, trip) => {
return Number(trip.clientFare) + (Number(acc) || 0)
})
console.log(totalCosts)
});
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment