Skip to content

Instantly share code, notes, and snippets.

@luizamboni
Last active August 22, 2017 17:37
Show Gist options
  • Save luizamboni/b7a63f6239c60ad15aaa7ead25d01342 to your computer and use it in GitHub Desktop.
Save luizamboni/b7a63f6239c60ad15aaa7ead25d01342 to your computer and use it in GitHub Desktop.
generator to create range of days
const moment = require("moment")
const rangeGenerator = function*(startDate, endDate) {
const start = moment(startDate)
const end = moment(endDate)
while (start.format("YYYY-MM-DD") <= end.format("YYYY-MM-DD")) {
yield start.format("YYYY-MM-DD")
start.add(1, "day")
}
}
for (const a of rangeGenerator("2017-01-01", "2017-03-30")) {
console.log(a)
}
Array.from(rangeGenerator("2017-01-01", "2017-03-30")).map(a => console.log(`teste ${a}`))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment