title: Remove duplicates from NSArray of Custom Objects also compare and edit same
body: <p>I have two <code>NSMutableArrays</code>. Each contains a custom word object in it. Custom word has 2 properties text and frequency. Now I want to combine these two <code>arrays</code> in such a way that, if these two arrays has same text in it, then it should compare the frequency of those two text and select the highest frequency of the two. And also it should remove the duplicates from the <code>array</code>.
  I tried every logic for this but was not able to do this. Can any body help me with the logic for this. Following the code. But it should also remove the duplicates.</p>
  
  <pre><code>for (int i = 0; i &lt; [array count]; i++) {
    for (int j = 0; j &lt; [array count]; j++)  {
      if ([[[array objectAtIndex:i]firstWord] isEqualToString:[[array objectAtIndex:j] firstWord]]) {
  
        if ([[array objectAtIndex:i] frequency] &lt; [[array objectAtIndex:j] frequency]) {
          CustomWordFrequency *word = [array objectAtIndex:i];
          word.frequency = [[array objectAtIndex:j] frequency];
          [array replaceObjectAtIndex:i withObject:word];
        }
  
      }
    }
  }
  </code></pre>