Created
June 22, 2018 00:23
-
-
Save caiogranero/f0a715e380d0284d9549795001c30557 to your computer and use it in GitHub Desktop.
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
const characters = [ | |
{ name: 'Professor', appearAt: '10/05/2017 10:10:10'}, | |
{ name: 'Nairobi', appearAt: '10/05/2017 12:10:10' }, | |
{ name: 'Tókyo', appearAt: '10/06/2017 07:10:10' }, | |
{ name: 'Rio', appearAt: '10/06/2017 09:10:10' }, | |
{ name: 'Denver', appearAt: '10/07/2018 11:10:10' }, | |
{ name: 'Berlim', appearAt: '10/07/2018 17:10:10' }, | |
{ name: 'Helsinque', appearAt: '15/04/2017 12:10:10' }, | |
{ name: 'Moscou', appearAt: '15/04/2017 12:10:10' }, | |
{ name: 'Raquel Murillo', appearAt: '10/09/2020 07:10:10' } | |
] | |
const dateFormat = 'DD/MM/YYYY HH:mm:ss' | |
const getCharacterByName = (name) => characters.find(character => character.name === name) | |
const findACharacterWhoAppearedBeforeAnyone = (name) => { | |
const mRioDate = moment(getCharacterByName(name).appearAt, dateFormat) | |
return characters.find(character => { | |
const mCurrentDate = moment(character.appearAt, dateFormat) | |
return mCurrentDate.isBefore(mRioDate) | |
}) | |
} | |
findACharacterWhoAppearedBeforeAnyone('Rio'); | |
// { name: 'Professor', appearAt: '10/05/2017 10:10:10'} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment