_.filter = function(collection, test) {
var result = [];
_.each(collection, function(value) {
if(test(value)) {
result.push(value);
}
})
return result;
};
_.reject = function(collection, test) {
var result = [];
return _.filter(collection, function(value) {
return !test(value);
})
};
I'm a bit puzzled by how this works. I have two underscore.js functions defined here in the same scope. If I pass a test array of random nums how does _.filter in _.reject work?
var isEven = function(num) { return num % 2 === 0; };
var odds = _.reject([1, 2, 3, 4, 5, 6], isEven);
expect(odds).to.eql([1, 3, 5]);
For example I test my functions and I get the assert is true but I don't understand how this works