Array.filter: max number of matches?

Alex Vincent ajvincent at gmail.com
Tue Nov 13 13:12:30 PST 2012


The some method, as currently implemented, isn't truly better.
Mathematically, I think Array.prototype.some would be equivalent to my
suggested Array.prototype.filter(callback, thisObj, 1);

On Tue, Nov 13, 2012 at 12:33 PM, Brendan Eich <brendan at mozilla.org> wrote:

> Andrea Giammarchi wrote:
>
>> wait, I might have misunderstood your problem ... so you want to stop
>> iterating, right ?
>>
>> When that is the case, you can simply drop the iteration like this:
>>
>> myArray.slice().filter(**function (value, index, original) {
>>   // do your stuff
>>   if (conditionSatisfied) {
>>     original.length = 0;
>>   }
>> });
>>
>> there, you can break the iteration as easy as that :-)
>>
>
> Making a copy and then mutating its length seems worse than using some,
> though.
>
> /be
>
>


-- 
"The first step in confirming there is a bug in someone else's work is
confirming there are no bugs in your own."
-- Alexander J. Vincent, June 30, 2001
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121113/26737f7e/attachment.html>


More information about the es-discuss mailing list