I want to iterate through an array, run a calculation, and if the condition is true for the result, return a new object. _.filter(...)
would not work here, since the iterator function must return either true
or false
.
_.map(people, function(person) {
var age = calculateAge(person.birthDate);
if (age > 50) {
return {person: person, age: age};
}
});
I've tried searching all over, including the documentation, but I haven't found a way to do this well.