Pure win: Array.from and Array.of

Dmitry A. Soshnikov dmitry.soshnikov at gmail.com
Sun Jul 10 04:18:36 PDT 2011


On 10.07.2011 15:14, Mike Shaver wrote:
> On Sun, Jul 10, 2011 at 7:09 AM, Dmitry A. Soshnikov
> <dmitry.soshnikov at gmail.com>  wrote:
>>> If I hadn't made map skip holes, then the fill pattern would be simple
>>> enough:
>>>
>>> Array(4).map(function (_,x) x * x);
>>>
>> It's in particular case, you try to multiply indices, which in current
>> implementation of `map` anyway gives unfortunately nothing.
> Yes, as I said it *would* work if map had been specified not to skip holes:
>

Oh, *would* -- I missed it. Sure, but if it *had*, I *wouldn't* mention 
it at all ;)

But `map` correctly skips holes, as it should -- to support sparse 
arrays. The issue is not in `map`, so that's why I mention `fill`.

Dmitry.

> js>  [undefined,undefined,undefined,undefined].map(function(_,x)x*x)
> [0, 1, 4, 9]
>
> Is that not what you want?
>
> Mike



More information about the es-discuss mailing list