Skip to content

Commit f56cbaa

Browse files
committed
Added map-reduce and find methods to list
1 parent 97513a4 commit f56cbaa

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lib/list.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,24 @@ if (_) {
115115
});
116116
}
117117

118-
['slice', 'forEach', 'filter'].forEach(function (method) {
118+
['slice', 'forEach', 'filter', 'reduce', 'map'].forEach(function (method) {
119119
var slice = [].slice;
120120
List.prototype[method] = function () {
121121
return Array.prototype[method].apply(this.items, slice.call(arguments));
122122
};
123-
});;
123+
});
124+
125+
List.prototype.find = function(pattern, field) {
126+
if (field) {
127+
var res;
128+
this.items.forEach(function(o) {
129+
if (o[field] == pattern) res = o;
130+
});
131+
return res;
132+
} else {
133+
return this.items[this.items.indexOf(pattern)];
134+
}
135+
};
124136

125137
List.prototype.toObject = function() {
126138
return this.items;

0 commit comments

Comments
 (0)