Created
March 30, 2018 17:30
-
-
Save cameronbaney/801c3babd5907284ab006e4abceec707 to your computer and use it in GitHub Desktop.
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
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