Skip to content

Instantly share code, notes, and snippets.

@cameronbaney
Created March 30, 2018 17:30
Show Gist options
  • Save cameronbaney/801c3babd5907284ab006e4abceec707 to your computer and use it in GitHub Desktop.
Save cameronbaney/801c3babd5907284ab006e4abceec707 to your computer and use it in GitHub Desktop.
window['moment-range'].extendMoment(moment);
const storage = [
["2017-11", 0],
["2018-3", 1964105]
]
const storageGaps = function() {
let gaps = []
storage.map((current, index) => {
if (storage.length > index + 1) {
const currentMonth = storage[index]
const nextMonth = getNextMonth(index + 1, storage)
gaps = gaps.concat(getRange(currentMonth, nextMonth))
}
})
return gaps
}
const sayX = x => console.log('x is ' + x);
const getNextMonth = (index, months) => R.compose(
R.head,
R.nth(index),
R.defaultTo([])
)(months)
const getRange = function(firstMonth, lastMonth) {
const range = moment.range(R.head(firstMonth), lastMonth)
const months = Array.from(range.by('month'))
const yoyo = months.map(m => [
m.format('YYYY-MM-DD'),
firstMonth[1]
])
return yoyo
}
console.log(storageGaps())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment