I am trying to chain these two method calls together:
utils.map([1,2,3,4,5], function (el) { return ++el; } )
and
utils.filter(function (el) {return !el%2; }
While both methods work fine individually, the following chained code is not functioning correctly. How can I modify this code to make it work?
utils
.map([1,2,3,4,5], function (el) { return ++el; })
.filter(function (el) { return !el%2; }
This is my utils
object:
var utils = {
each: function (collection, iteratee){
return collection.forEach(iteratee);
},
map: function (collection, iteratee) {
return collection.map(iteratee);
},
filter: function (collection, predicate) {
return collection.filter(predicate);
},
find: function (collection, predicate) {
return collection.find(predicate);
}
}
I understand that when chaining methods, the arguments need to be adjusted and only the iteratee should be provided instead of the whole collection. How can I achieve this?
Thank you for your help. I am willing to learn more about any specific concepts if needed.