Last active
June 10, 2018 05:47
-
-
Save ndabAP/606c55fe5d9adc07f93b15ce0043e7db to your computer and use it in GitHub Desktop.
Return days relative to first day
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
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