Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const learnedSomething = () => Math.random() <= .5;
- const alive = (d) => d.getFullYear() <= 2017;
- const now = new Date(2017, 7, 1);
- const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
- const tomorrow = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate() + 1);
- const life = (function* (today) {
- while (alive(today))
- yield { date: today = tomorrow(today), learnedSomething: learnedSomething() };
- })(today);
- let stringDate;
- let prevStringDate;
- for (let day of life) {
- console.log(day.date);
- stringDate = day.date.toLocaleDateString('en', { day: 'numeric', month: 'long', year: 'numeric', weekday: 'long' });
- if (stringDate === prevStringDate) {
- throw new Error('Invalid date calculation');
- }
- console.log(`${stringDate} was ${day.learnedSomething ? 'a decent day' : 'ok'}`);
- prevStringDate = stringDate;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement