Skip to content

Instantly share code, notes, and snippets.

@gfranko
Created May 16, 2014 06:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gfranko/b9f4d9e5773db83760cb to your computer and use it in GitHub Desktop.
Save gfranko/b9f4d9e5773db83760cb to your computer and use it in GitHub Desktop.
.each() JavaScript implementation
function each (collection, callback) {
var x, len;
if(Utils.isArray(collection)) {
x = -1;
len = collection.length;
while(++x < len) {
if (callback(x, collection[x]) === false) {
break;
}
}
} else if(Utils.isPlainObject(collection)) {
for(x in collection) {
if(collection.hasOwnProperty(x)) {
if (callback(x, collection[x]) === false) {
break;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment