repeatD(10) returns 17 copies, not 10.
On Tue, Jan 3, 2012 at 4:28 AM, Herby Vojčík <he...@mailbox.sk> wrote: > Hello, > > binary ftw. See http://jsperf.com/array-repeat/4 Array.prototype.repeatD. > And I also tried push.apply in repeatC (not to copy over the array using > concat but grow it in place until possible) and it really surprised me it > was that much slower. Concat is probably heavily optimized. > > Herby > > -----Pôvodná správa----- From: Rick Waldron > Sent: Tuesday, January 03, 2012 2:21 AM > To: Adam Shannon > Cc: es-discuss@mozilla.org ; Mariusz Nowak > Subject: Re: Suggestion: Array.prototype.repeat > > > > > > On Mon, Jan 2, 2012 at 5:55 PM, Adam Shannon <a...@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 > > > _______________________________________________ > es-discuss mailing list > es-discuss@mozilla.org > https://mail.mozilla.org/listinfo/es-discuss _______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss