callback function with underscore _.each() <p>I'm trying to implement an _.each() (that I wrote) inside another function and I keep getting "undefined" returned to me. I'm trying to use _.each() to apply a test function to an array. I know this a simple callback syntax issue, but its perplexing me. </p> <p>thanks in advance from a noob.</p> <p>here's my function:</p> <pre><code>_.filter = function(collection, test) { _.each(collection, test()); }; </code></pre> <p>this returns 'undefined'</p> <p>this is the array i'm passing as 'collection':</p> <pre><code>[1, 2, 3, 4, 5, 6] </code></pre> <p>this is the function i'm passing as 'test': </p> <pre><code>function (num) { return num % 2 !== 0; } </code></pre> <p>here's my _.each():</p> <pre><code>_.each = function(collection, iterator) { if( Object.prototype.toString.call( collection ) === '[object Array]' ) { for (var i=0; i&lt;collection.length; i++){ iterator(collection[i], i, collection); } } else if (typeof collection === 'object'){ for (var i in collection){ iterator(collection[i], i, collection) } } else if (typeof collection === 'int'){ console.log('int') } }; </code></pre>