Skip to content

Instantly share code, notes, and snippets.

@basekays
Created January 24, 2017 19:38
Show Gist options
  • Select an option

  • Save basekays/3e2e080cfe1dde35c480411adee5b30d to your computer and use it in GitHub Desktop.

Select an option

Save basekays/3e2e080cfe1dde35c480411adee5b30d to your computer and use it in GitHub Desktop.
_.each syntax
// Call iterator(value, key, collection) for each element of collection.
// Accepts both arrays and objects.
//
// Note: _.each does not have a return value, but rather simply runs the
// iterator function over each item in the input collection.
_.each = function(collection, iterator) {
_.each(collection, iterator(value, key, collection) {
}
};
@basekays

Copy link
Copy Markdown
Author

_.each = function(collection, iterator) {
if (Array.isArray(collection)) {
for (var i = 0; i<collection.length; i++) {
_.each(iterator (value, key, collection)) {

    }
  }
}

};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment