Skip to content

Commit

Permalink
Handle zero length arrays properly
Browse files Browse the repository at this point in the history
  • Loading branch information
kriszyp committed Jul 28, 2011
1 parent 9d4a046 commit 647dc9c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions each.js
Expand Up @@ -18,30 +18,30 @@ define([], function(){
if(callback.length > 2){
emit = getEmit(result = []);
}
if(array.length > -1){
if(length > -1){
if(thisObject){
// iterate over array
do{
for(;i < length; i++){
// call the callback
var newValue = callback.call(thisObject, array[i], i, emit);
// if a value was returned, examine it
if(newValue !== undefined){
// defined value breaks out of loop
return newValue;
}
}while(++i < length);
}
}else{
// we do a separate branch for when thisObject isn't provided because
// it is faster to avoid the .call()
do{
for(;i < length; i++){
// call the callback
var newValue = callback(array[i], i, emit);
// if a value was returned, examine it
if(newValue !== undefined){
// defined value breaks out of loop
return newValue;
}
}while(++i < length);
}
}
}else{
// not an array, iterate over an object
Expand Down

0 comments on commit 647dc9c

Please sign in to comment.