Skip to content

Instantly share code, notes, and snippets.

@eternal44
Created December 4, 2015 00:07
Show Gist options
  • Save eternal44/d00836d8320f613e011f to your computer and use it in GitHub Desktop.
Save eternal44/d00836d8320f613e011f to your computer and use it in GitHub Desktop.
else / else if review
function each(collection, predicate){
if (Array.isArray(collection) || typeof collection === 'string'){
for (var i = 0; i < collection.length; i++){
predicate(collection[i]);
}
} else if(typeof collection === 'object') {
for (var j in collection){
predicate(collection[j]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment