Skip to content

Instantly share code, notes, and snippets.

@ndabAP
Last active June 10, 2018 05:47
Show Gist options
  • Save ndabAP/606c55fe5d9adc07f93b15ce0043e7db to your computer and use it in GitHub Desktop.
Save ndabAP/606c55fe5d9adc07f93b15ce0043e7db to your computer and use it in GitHub Desktop.
Return days relative to first day
import moment from 'moment'
import flow from 'lodash/flow'
import map from 'lodash/fp/map'
/**
* Returns days relative to first one, e. g.: 0, 2, 9, 10, 11
*
* @params {array} dates
* @returns {array}
*/
export const getRelativeDays = dates => {
const initial = moment(dates.shift())
return flow([
map(date => moment(date).diff(initial, 'days')),
days => {
days.splice(0, 0, 0)
return days
}
])(dates)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment