Re: Suggestion: Array.prototype.repeat

2012-01-03 Thread Mariusz Nowak
Rick Waldron wrote: On Mon, Jan 2, 2012 at 3:56 PM, Mariusz Nowak medikoo+mozilla@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. Is the controversy editorial or

Re: Suggestion: Array.prototype.repeat

2012-01-03 Thread Herby Vojčík
. 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

Re: Suggestion: Array.prototype.repeat

2012-01-03 Thread felix
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

Re: Suggestion: Array.prototype.repeat

2012-01-03 Thread Rick Waldron
On Tue, Jan 3, 2012 at 3:34 AM, Mariusz Nowak medikoo+mozilla@medikoo.com wrote: Rick Waldron wrote: On Mon, Jan 2, 2012 at 3:56 PM, Mariusz Nowak medikoo+mozilla@medikoo.com wrote: I like it, it indeed looks very logical, however it's a bit controversial that we need

Re: Suggestion: Array.prototype.repeat

2012-01-03 Thread Herby Vojčík
, January 03, 2012 2:30 PM To: Herby Vojčík Cc: Rick Waldron ; Adam Shannon ; Mariusz Nowak ; es-discuss@mozilla.org Subject: Re: Suggestion: Array.prototype.repeat 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

Re: Suggestion: Array.prototype.repeat

2012-01-03 Thread Mariusz Nowak
Rick Waldron wrote: On Tue, Jan 3, 2012 at 3:34 AM, Mariusz Nowak medikoo+mozilla@medikoo.com wrote: Rick Waldron wrote: On Mon, Jan 2, 2012 at 3:56 PM, Mariusz Nowak medikoo+mozilla@medikoo.com wrote: I like it, it indeed looks very logical, however it's a bit

Re: Suggestion: Array.prototype.repeat

2012-01-03 Thread Rick Waldron
On Tue, Jan 3, 2012 at 9:19 AM, Mariusz Nowak medikoo+mozilla@medikoo.com wrote: Rick Waldron wrote: On Tue, Jan 3, 2012 at 3:34 AM, Mariusz Nowak medikoo+mozilla@medikoo.com wrote: Rick Waldron wrote: On Mon, Jan 2, 2012 at 3:56 PM, Mariusz Nowak

Re: Suggestion: Array.prototype.repeat

2012-01-03 Thread Greg Smith
What is the use case for .repeat? Trying to imagine some code where I'd need it so I can get a feel for how it should work. On Tue, Jan 3, 2012 at 9:19 AM, Mariusz Nowak medikoo+mozilla@medikoo.com wrote: Rick Waldron wrote: On Tue, Jan 3, 2012 at 3:34 AM, Mariusz Nowak

Re: Suggestion: Array.prototype.repeat

2012-01-03 Thread Mariusz Nowak
Rick Waldron wrote: On Tue, Jan 3, 2012 at 9:19 AM, Mariusz Nowak medikoo+mozilla@medikoo.com wrote: Rick Waldron wrote: On Tue, Jan 3, 2012 at 3:34 AM, Mariusz Nowak medikoo+mozilla@medikoo.com wrote: Rick Waldron wrote: On Mon, Jan 2, 2012 at 3:56 PM,

Re: Suggestion: Array.prototype.repeat

2012-01-03 Thread Rick Waldron
On Tue, Jan 3, 2012 at 10:16 AM, Mariusz Nowak medikoo+mozilla@medikoo.com wrote: Rick Waldron wrote: On Tue, Jan 3, 2012 at 9:19 AM, Mariusz Nowak medikoo+mozilla@medikoo.com wrote: Rick Waldron wrote: On Tue, Jan 3, 2012 at 3:34 AM, Mariusz Nowak

Array.range() (was: Suggestion: Array.prototype.repeat)

2012-01-03 Thread Axel Rauschmayer
On Jan 3, 2012, at 15:46 , Greg Smith wrote: What is the use case for .repeat? Trying to imagine some code where I'd need it so I can get a feel for how it should work. So beauty alone does not count? ;-) It’s true – there are not a lot of use cases for Array.repeat(). But I keep thinking

Re: Array.range() (was: Suggestion: Array.prototype.repeat)

2012-01-03 Thread Rick Waldron
I think it's fairly common for range implementations to provide an optional `step` parameter On Tue, Jan 3, 2012 at 12:08 PM, Axel Rauschmayer a...@rauschma.de wrote: On Jan 3, 2012, at 15:46 , Greg Smith wrote: What is the use case for .repeat? Trying to imagine some code where I'd need it

Re: Array.range() (was: Suggestion: Array.prototype.repeat)

2012-01-03 Thread Axel Rauschmayer
I think it's fairly common for range implementations to provide an optional `step` parameter Good point. Maybe all of these parameters should be options: Array.range() - 0, 1, 2, 3, ... Array.range({ start: 3 }) - 3, 4, 5, 6, ... Array.range({ end: 5 }) - 0, 1, 2, 3, 4 Array.range({ step: 3

Re: Array.range() (was: Suggestion: Array.prototype.repeat)

2012-01-03 Thread Sean Eagan
I think step should be 0, and step towards end: Array.range({start: 5, end: 0, step: 2}) - 5, 3, 1 On Tue, Jan 3, 2012 at 11:42 AM, Axel Rauschmayer a...@rauschma.de wrote: I think it's fairly common for range implementations to provide an optional `step` parameter Good point. Maybe all of

Re: Array.range() (was: Suggestion: Array.prototype.repeat)

2012-01-03 Thread Axel Rauschmayer
Either way is fine with me. But it’s probably best to copy Python’s semantics: http://docs.python.org/py3k/library/functions.html#range On Jan 3, 2012, at 18:50 , Sean Eagan wrote: I think step should be 0, and step towards end: Array.range({start: 5, end: 0, step: 2}) - 5, 3, 1 On Tue,

Re: Array.range() (was: Suggestion: Array.prototype.repeat)

2012-01-03 Thread Adam Shannon
I would be more in favor of something like the code below, its just a proof of concept. Array.prototype.range = function (value, start, end, step) { if (typeof value === number) { end = (start = 0 value = 0) ? Math.min(value, start) : 0; start = (start = 0 value = 0) ?

Re: Array.range() (was: Suggestion: Array.prototype.repeat)

2012-01-03 Thread Rick Waldron
On Tue, Jan 3, 2012 at 12:50 PM, Sean Eagan seaneag...@gmail.com wrote: I think step should be 0, and step towards end: Array.range({start: 5, end: 0, step: 2}) - 5, 3, 1 This would be an unfortunate limitation, considering real world impl's allow negative numbers...

Re: Array.range() (was: Suggestion: Array.prototype.repeat)

2012-01-03 Thread Maël Nison
Good point. Maybe all of these parameters should be options: Array.range() - 0, 1, 2, 3, ... Array.range({ start: 3 }) - 3, 4, 5, 6, ... Array.range({ end: 5 }) - 0, 1, 2, 3, 4 Array.range({ step: 3 }) - 0, 3, 6, 9, ... Array.range({ start: -2, step: -1 }) - -2, -3, -4, -5, ... etc. Why

Re: Array.range() (was: Suggestion: Array.prototype.repeat)

2012-01-03 Thread Michael A. Smith
When I first started learning JavaScript I didn't understand how new Array(n); worked, in that it creates an empty array with a length of n. What I had expected was an array with n values (even if it wasn't well-defined what those values should be). So of course my attempt to create an array of

Re: Suggestion: Array.prototype.repeat

2012-01-03 Thread Nadav Shesek
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

Suggestion: Array.prototype.repeat

2012-01-02 Thread Axel Rauschmayer
Array.prototype.repeat seems like a logical dual to String.prototype.repeat: http://wiki.ecmascript.org/doku.php?id=harmony:string.prototype.repeat Implementation: Array.prototype.repeat = function (times) { var result = []; var len = this.length; var resultLen =

Re: Suggestion: Array.prototype.repeat

2012-01-02 Thread Mariusz Nowak
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, currently I'm using something like that: var slice = Array.prototype.slice;

Re: Suggestion: Array.prototype.repeat

2012-01-02 Thread Michael A. Smith
On Mon, Jan 2, 2012 at 3:56 PM, Mariusz Nowak medikoo+mozilla@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

Re: Suggestion: Array.prototype.repeat

2012-01-02 Thread Adam Shannon
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() On Mon, Jan 2, 2012 at 16:51, Michael A.

Re: Suggestion: Array.prototype.repeat

2012-01-02 Thread Rick Waldron
On Mon, Jan 2, 2012 at 3:56 PM, Mariusz Nowak medikoo+mozilla@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. Is the controversy editorial or fact, because the following

Re: Suggestion: Array.prototype.repeat

2012-01-02 Thread Rick Waldron
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