Permalink
Browse files
Handle zero length arrays properly
- Loading branch information...
Showing
with
5 additions
and
5 deletions.
-
+5
−5
each.js
|
@@ -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
|
|
|
0 comments on commit
647dc9c