Skip to content

Instantly share code, notes, and snippets.

@caiogranero
Created June 22, 2018 00:16
Show Gist options
  • Save caiogranero/03268b2c34115b739a1648555572b990 to your computer and use it in GitHub Desktop.
Save caiogranero/03268b2c34115b739a1648555572b990 to your computer and use it in GitHub Desktop.
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 setWeekDayAsKey = () => {
return characters.map(character => {
const mCurrentDate = moment(character.appearAt, dateFormat)
return Object.assign(character, { weekDay: mCurrentDate.format('dddd') })
})
}
/**
* { name: 'Professor', appearAt: '10/05/2017 10:10:10', weekDay: 'Wednesday'},
* { name: 'Nairobi', appearAt: '10/05/2017 12:10:10', weekDay: 'Wednesday' },
* { name: 'Tókyo', appearAt: '10/06/2017 07:10:10', weekDay: 'Saturday' },
* { name: 'Rio', appearAt: '10/06/2017 09:10:10', weekDay: 'Saturday' },
* { name: 'Denver', appearAt: '10/07/2018 11:10:10', weekDay: 'Tuesday' },
* { name: 'Berlim', appearAt: '10/07/2018 17:10:10', weekDay: 'Tuesday' },
* { name: 'Helsinque', appearAt: '15/04/2017 12:10:10', weekDay: 'Saturday' },
* { name: 'Moscou', appearAt: '15/04/2017 12:10:10', weekDay: 'Saturday' },
* { name: 'Raquel Murillo', appearAt: '10/09/2020 07:10:10', weekDay: 'Thursday' }
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment