Skip to content

Commit

Permalink
Merge pull request #20 from toonketels/findLast-improve_performance_b…
Browse files Browse the repository at this point in the history
…y_returning_immediately

Improve performance findLast by returning immediately
  • Loading branch information
tj committed Feb 17, 2013
2 parents 0ad86ab + c292d69 commit 737638c
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions index.js
Expand Up @@ -289,15 +289,13 @@ proto.find = function(fn){

proto.findLast = function(fn){
fn = toFunction(fn);
var ret;
var val;
var vals = this.__iterate__();
var len = vals.length();
for (var i = 0; i < len; ++i) {
for (var i = len - 1; i > -1; --i) {
val = vals.get(i);
if (fn(val, i)) ret = val;
if (fn(val, i)) return val;
}
return ret;
};

/**
Expand Down

0 comments on commit 737638c

Please sign in to comment.