I have an array of objects with a key mediaand a value, which may or may not be empty. I have a function to select this key value and a function that checks that the value is empty, so that mediaEmptyComparer({media: ''})returns true and mediaEmptyComparer({media: 'somevalue'})false.
var array = _.times(100, function () { return {media: Math.random() < 0.5 ? '' : 'value'} });
var mediaPicker = _.partialRight(_.get, 'media');
var mediaEmptyComparer = _.flow(mediaPicker, _.isEmpty);
var splittedArray = _.filter(array, mediaEmptyComparer);
console.log(splittedArray);
When I try to use a function like the predicate for _.filter, it always fails (as in the example), but if I write:
var splittedArray = _.filter(array, function (x) { return mediaEmptyComparer(x);});
it works. This is similar to the fact that the value for each iteration is not passed as an argument to the function. Any help? Thanks
source
share