On Thu, Jul 5, 2012 at 11:49 PM, Jussi Kalliokoski <[email protected]> wrote: > The only case where I've had a problem with forEach, map and friends > skipping holes is when I want a quick (to type) way to create a populated > array, say I wanted to do something like > > var powersOf2 = Array(16).map((item, index) => Math.pow(2, index)) > > But that leads me to suggest Array.create() that would be another FP goodie, > simplifies things as `item` becomes irrelevant: > > var powersOf2 = Array.create(16, (index) => Math.pow(2, index)) > > What do you think? > > This being instead of the current: > > var powersOf2 = [] > > for (var index=0; index<16; index++) { > powersOf2.push(Math.pow(2, index)) > } > > I think it would align well with all these other array helpers.
Once we have for-of and generators, making a range() generator that accomplishes the same thing is trivial, and more powerful. (Arbitrary start/end/step.) ~TJ _______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

