1

Closed

Select method: Stop calling "clause" twice for each element

description

Out of curiosity, in the Select method, why not call the clause function once, then if the result evaluates to true, add it to the array? This would roughly double performance of select.
 
So, from:
 
for (var i = 0; i < this.items.length; i++) {
if (clause(this.items[i])) {
 newArray[newArray.length] = clause(this.items[i]);
}
}
 

 
To this:
 
for (var i = 0; i < this.items.length; i++) {
 
var result = clause(this.items[i]);
if (result)
 newArray[newArray.length] = result;
}
 

 
-- Curtis
Closed Jun 16, 2009 at 11:05 PM by crpietschmann
Done

comments