We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8e477f5 commit ab5fb7bCopy full SHA for ab5fb7b
src/underbar.js
@@ -50,6 +50,17 @@ var _ = {};
50
// Note: _.each does not have a return value, but rather simply runs the
51
// iterator function over each item in the input collection.
52
_.each = function(collection, iterator) {
53
+ //test if collection is array
54
+ if (Array.isArray(collection)) {
55
+ for (var i=0; i<collection.length; i++) {
56
+ iterator(collection[i], i, collection);
57
+ }
58
+ //otherwise treat as object
59
+ } else {
60
+ for (var j in collection) {
61
+ iterator(collection[j], j, collection);
62
63
64
};
65
66
// Returns the index at which value can be found in the array, or -1 if value
0 commit comments