var people = [
{firstName : \"Thein\", city : \"ny\", qty : 5},
{firstName : \"Michael\", city : \"ny\", qty : 3},
{firstName : \"Bloom\", city : \"nj\", qty
YAAUu-Yep Another Answer Using underscore...
// use a proper browser to run this code snippet, a browser that is es6-compliant
let people = [{
firstName: "Thein",
city: "ny",
qty: 5
},
{
firstName: "Michael",
city: "ny",
qty: 3
},
{
firstName: "Bloom",
city: "nj",
qty: 10
}
];
// either you pick the properties you want
let picking = _.iteratee((person) => _(person).pick("firstName", "city"));
// either you omit the properties you do not want
let omitting = _.iteratee((person) => _(person).omit("qty"));
// create the filter by city
let living = (people, city) => _(people).where({
"city": city
});
// put the "filter by city" into a mixin (as I assume it would be used again & again)
_.mixin({
living: living
});
// do the thing (twice),
// these chaining methods could be done into a mixin as well
console.log("results by picking properties:", _(people).chain().living("ny").map(picking).value());
console.log("results by omitting properties:", _(people).chain().living("ny").map(omitting).value());