title: preserving properties when using jQuery grep
body: <p>I'm taking an object array and extracting only the unique objects from it WHILE manipulating it. I started with inArray, but I'm testing a nested property, so it doesn't work so well. grep will test nested properties but it doesn't allow me to alter the objects before ending up with the final array. </p>
  
  <p>Let me demonstrate:</p>
  
  <p>This is (similar to) my starting object array:
  It's got properties (eg: foo, legs.type) that I don't use in my algorithm, but their presence complicates the object structure and thus the solution.</p>
  
  <pre><code> var critters = [
      {'legs':{'num':4,'type':'paw'},     'species':'cat',    'foo':11 },
      {'legs':{'num':4,'type':'paw'},     'species':'dog',    'foo':11 },
      {'legs':{'num':2,'type':'foot'},    'species':'human',  'foo':23 },
      {'legs':null,                       'species':'fish',   'foo':3 }
  ];
  </code></pre>
  
  <p>This is the object array I want at the end:</p>
  
  <pre><code>// walkingCritterTypes = [
  //   { 'legs':{'num':4,'type':'paw'},     'species':['cat','dog'],    'foo':11 },
  //   { 'legs':{'num':2,'type':'foot'},    'species':['human'],        'foo':23 }
  // ];
  </code></pre>
  
  <p>Here's my approach using inArray. 
  The + is that is allows me to grasp the items and manipualgte it before passing it tot he final array.
  The - is that is doesn't work because it needs to test a nest property.</p>
  
  <pre><code>var walkingCritterTypesA = [];
  angular.forEach(critters,function(critter,i){
      if (angular.isObject(critter.legs)) {// ditch critters with null legs
          var exists = $.inArray(critter.legs.num, walkingCritterTypes.legs.num);
          //this does not work
          // I want it to find if walkingCritterTypes.legs.num already exists
          if (exists){
              // but if it did magically work, it would allow me to 
              // operate on the walkingCritterTypes array item, 
              // adding this critter's properties (eg species) to the final array
              walkingCritterType[i].species.push(critter.species);
          }
          else{
              // this is a new type, so I'll add it
              walkingCritterType = {};
              walkingCritterType.legs = critter.legs;
              walkingCritterType.species = critter.species;
              walkingCritterType.foo = critter.foo;
              walkingCritterTypesA.push(walkingCritterType);
          }
      }
  });
  console.log(walkingCritterTypesA);
  </code></pre>
  
  <p>Here's my approach using grep.
  The + is that it can search a nested property.
  The -'s are that 1] I'm not sure howe to write the test, and 2] it's magic - it simply hands me a new array at the end, without giving me a chance to manipulate it</p>
  
  <pre><code>angular.forEach(critters,function(critter,i){
      if (angular.isObject(critter.legs)) {// I don't care about critters with null legs
          walkingCritterTypesG2 = $.grep(walkingCritterTypesG, function(el,i){
              return // er what? compare it to itself??
          })
      }
  });
  
  
  console.log(walkingCritterTypesG);
  </code></pre>
  
  <p>Not sure how to reconcile these two.</p>