This approach is not performant nor particularly elegant. Check out [super-collection(https://github.com/nickb1080/super-collection) for a much better implementation.
Collection is a simple JS class with the “collection methods” from Lo-Dash/Underscore mixed into the prototype. To enable easy chaining, methods that would ordinarily return arrays return instances of Collection instead.
forEach, each, eachRight, forEachRight, map, collect, filter, select, where, pluck, reject, invoke, initial, rest, tail, drop, compact, flatten, without, shuffle, remove, transform, unique, uniq, union, intersection, and difference.
reduce, foldl, inject, reduceRight, foldr, find, detect, findWhere, every, all, some, any, contains, max, min, include, size, first, last, indexOf, lastIndexOf, isEmpty, toArray, at, findLast, indexBy, sortBy, and countBy.