Last active
August 22, 2017 17:37
-
-
Save luizamboni/b7a63f6239c60ad15aaa7ead25d01342 to your computer and use it in GitHub Desktop.
generator to create range of days
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 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