Array.filter: max number of matches?

Roger Andrews roger.andrews at mail104.co.uk
Wed Nov 14 07:39:31 PST 2012


Nb: A limit is consistent with String.prototype.split which has an optional limit in the range [0:4294967295] to avoid excessiveness.

(no great insight, but interesting?)


-----------------
From: Alex Vincent 
Sent: Tuesday, November 13, 2012 2:07 AM
To: es-discuss at mozilla.org 
Subject: Array.filter: max number of matches?


I've been wondering for a while if it would be a good idea to add an argument to Array.prototype.filter, for a maximum number of matches.  For example, if I have a thousand-element array and I only want three matches, it might make sense to truncate the search after the third match.

Put another way:  if I want an intersection between two arrays treated as sets, and one array has only three members, then once I've found matches for those three, it really doesn't make sense to keep iterating.

Thoughts, anyone?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121114/99e327d8/attachment.html>


More information about the es-discuss mailing list