My favorites | Sign in
Project Home Downloads Wiki Issues Source Code Search
New issue   Search
  Advanced search   Search tips   Subscriptions
Issue 1451: Array.forEach, filter, some, etc. are not special-cased for sparse arrays.
2 people starred this issue and may be notified of changes. Back to list
Status:  New
Owner:  ----

Sign in to add a comment
Reported by, Jun 10, 2011
Array.forEach, filter, some, every, map, reduce and reduceRight don't special-case for sparse arrays. They loop from 0 to length-1.

Jun 13, 2011
Project Member #1
The reason they loop without attempting to special case for sparse arrays is that the callback function can add elements to the array being iterated. These are supposed to be included in the iteration. Therefore we cannot compute the indices up front as we do with other array methods. We need a mechanism to bail out when an element is added.
Oct 2, 2012
Getting out of memory problems in Node for this.

Problem occurs with a very large sparse array - first index value that is not undefined is in the millions.

With code of the form below, the debug statement never appears and an out of memory error is reported after a couple of minutes.

var res = this.sparse.filter(function(x,i,a)
return (x.isLoggedOn && (x.smallArr.indexOf(groupId) != -1));

Sign in to add a comment

Powered by Google Project Hosting