Closed jamesmorgan closed 8 years ago
Thanks!
Yeah, you have to recreate it. There wouldn't be anything wrong with adding a reset()
function, but they're super cheap to make (all the work is in the iteration itself), so it's probably not necessary. Here's what I'd do:
function makeDayRange(startDate, endDate){
var t = moment(startDate).startOf('day').twix(moment(endDate).startOf('day'));
return function(){
return t.iterate('days');
};
};
var range = makeDayRange(start, end);
//use it
var r = range();
r.next(); //etc
//reset it
range().next();
If this kind of thing doesn't meet your needs, LMK and I can reopen.
Thanks, that factory method should suffice. :+1:
Hi, thanks for a wicked library its saved me lots of time.
Do you know if there is a nice way to reset a twix iterator?
I want to re-use a iterator several times but I need to always create a new one like as follows. (basic example)
Is there a inbuilt way e.g.
range.reset()
or is the preferred way to simply create a new one each time?Many thanks
James