Skip to content

Instantly share code, notes, and snippets.

@uguisu-an
Last active August 9, 2019 23:14
Show Gist options
  • Save uguisu-an/16f583949a91162aec477f9feead0080 to your computer and use it in GitHub Desktop.
Save uguisu-an/16f583949a91162aec477f9feead0080 to your computer and use it in GitHub Desktop.
整列した日付の配列を月ごとに分ける
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