Last active
August 29, 2018 13:06
-
-
Save oleg-koval/cb9f43ef576e6c49e98db2b291e26581 to your computer and use it in GitHub Desktop.
get-latest-dates.js
This file contains hidden or 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
// 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