Skip to content

Instantly share code, notes, and snippets.

@oleg-koval
Last active August 29, 2018 13:06
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 oleg-koval/cb9f43ef576e6c49e98db2b291e26581 to your computer and use it in GitHub Desktop.
Save oleg-koval/cb9f43ef576e6c49e98db2b291e26581 to your computer and use it in GitHub Desktop.
get-latest-dates.js
// const test = [
// {
// arrival: '2018-08-21T13:35:00Z',
// departure: '2018-08-21T16:35:00Z',
// },
// {
// arrival: '2018-08-21T19:35:00Z',
// departure: '2018-08-21T16:35:00Z',
// },
// {
// arrival: '2018-08-21T10:35:00Z',
// departure: '2018-08-21T16:35:00Z',
// }
// ]
const getRecentHistory = (histories, key) => histories.reduce((p, c) => {
const d1 = new Date(p[key]).getTime()
const d2 = new Date(c[key]).getTime()
return d1 > d2 ? p : c
}, {})[key]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment