Suggestion: Array.prototype.repeat

Rick Waldron waldron.rick at gmail.com
Mon Jan 2 17:21:49 PST 2012


On Mon, Jan 2, 2012 at 5:55 PM, Adam Shannon <adam at ashannon.us> wrote:

> Another thing to think about is that .repeat (both on String and
> Array) will be used a lot in production. So it would make sense for
> each solution to be optimized for their specific case. It doesn't make
> sense to slow down something as trivial as .repeat()
>

Creating a 10000 item array by repeating a 1000 item array 10 times, the
difference is negligible when compared the implementation that I wrote, not
the one given above

http://jsperf.com/array-repeat/2

Also, note that I had to "make up" my own Array.repeat() because the
Array.generate shown above did not create the same return as the initial
Array.prototype.repeat(), but I stuck to the concepts laid out - no new
array is initialized (except that Array.prototype.slice _does_ initialize a
new Array() ).

Rick



>
> On Mon, Jan 2, 2012 at 16:51, Michael A. Smith <michael at smith-li.com>
> wrote:
> > On Mon, Jan 2, 2012 at 3:56 PM, Mariusz Nowak
> > <medikoo+mozilla.org at medikoo.com> wrote:
> >
> >> I like it, it indeed looks very logical, however it's a bit
> controversial
> >> that we need to create temporary array object to get one that we want.
> >> Function (not method) that returns generated array may make more sense…
> >
> > Is the difference in overhead between instantiating a new array and
> > using Array.prototype.slice.call on arguments really worth sacrificing
> > consistency with the proposed string.prototype.repeat and the very
> > clean syntax of someArray.repeat(n)?
> >
> > Michael A. Smith
> > Web Developer
> > True Action Network (an eBay company)
> > _______________________________________________
> > es-discuss mailing list
> > es-discuss at mozilla.org
> > https://mail.mozilla.org/listinfo/es-discuss
>
>
>
> --
> Adam Shannon
> Web Developer
> University of Northern Iowa
> Sophomore -- Computer Science B.S. & Mathematics
> http://ashannon.us
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120102/93634e29/attachment.html>


More information about the es-discuss mailing list