Iterative iterative animation in javascript using underscore

I caught myself using this instead of the traditional loop:

_.each(_.range(count), function(i){ ... }); 

The disadvantage is the creation of an unnecessary array of sizes.

However, I prefer semantics, for example .each (.range (10,0, -1), ...); upon repeated repetition.

Is there a way to do lazy range iteration, e.g. with pythons xrange?

+4
source share
3 answers

Given the source of underscore.js , the following is said about range :

Create an integer array containing arithmetic progression

I doubt there is a way to do lazy iteration without changing the source.

+2
source

If you don't mind keeping your hands dirty, take a look at the sources of the older but stable and full-featured MochiKit Iter . He is trying to create something along the lines of Python itertools .

+2
source

Just a note:

 _.each(_.range(count), function(i){ ... }); 

equivalently

 _.times(count, function(i){ ... }); 

little beautiful ...

+2
source

All Articles