Skip to content

Instantly share code, notes, and snippets.

@jpbassalot
Created March 1, 2014 22:09
Show Gist options
  • Select an option

  • Save jpbassalot/9298244 to your computer and use it in GitHub Desktop.

Select an option

Save jpbassalot/9298244 to your computer and use it in GitHub Desktop.

Revisions

  1. jpbassalot created this gist Mar 1, 2014.
    16 changes: 16 additions & 0 deletions new_gist_file_0
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    var aaa = [
    {name: "AAA", id: 845},
    {name: "BBB", id: 839},
    {name: "CCC", id: 854}
    ];
    var bbb = [
    {id: 839},
    {id: 854}
    ];

    var ids = {};
    _.each(bbb, function (bb) { ids[bb.id] = true; });

    var out = _.filter(aaa, function (val) {
    return ids[val.id];
    }, bbb);