Created
December 4, 2015 00:07
-
-
Save eternal44/d00836d8320f613e011f to your computer and use it in GitHub Desktop.
else / else if review
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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