Last active
August 9, 2019 23:14
-
-
Save uguisu-an/16f583949a91162aec477f9feead0080 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
const { isLastDayOfMonth } = require("date-fns"); | |
const eachMonth = (ds, ms = []) => { | |
if (ds.length === 0) return ms; | |
const i = ds.findIndex(isLastDayOfMonth); | |
if (i < 0) { | |
return eachMonth([], [...ms, ds]); | |
} else { | |
return eachMonth(ds.slice(i + 1), [...ms, ds.slice(0, i + 1)]); | |
} | |
}; | |
module.exports = eachMonth; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment