Removing duplicate elements in two arrays while assigning a greater score
<p>I have 2 arrays which contains objects as follows. </p>

<pre><code>var arrayl = {
 1: {url:google.com, score:0},
 2: {url:bing.com, score: 2},
 3: {url:yahoo.com, score: 0},
 4: {url:facebook.com, score: 5},
 5: {url:dopgile.com, score: 1},
 6: {url:ask.com, score: 10}, 
 7: {url:duckduckgo.com, score: 10}
},

array2 = {
 1: {url:google.com, score: 2},
 2: {url:facebook.com, score: 3}, 
 3: {url:twitter.com, score: 0},
 4: {url:duckduckgo.com, score: 0},
 5: {url:mamma.com, score: 4},
 6: {url:myspace.com, score: 5}
}; 
</code></pre>

<p>Array 1 and Array 2 both have unique elements within themselves. However there are duplicates among them. </p>

<p>I want to merge Array 2 with Array 1 in such a way as to increase the score of the duplicate element in Array 1 by 1 when it occurs.</p>

<p>For example, google.com is present in array 2 and array 1. When the merging process begins, it increases the score of the first element of array 1 which is google.com to 1 instead of 0. It shouldn't add the first element of array2 to it since it is a duplicate. </p>

<p>Similarly, the elements 2,3,5,6 will be merged without increasing any scores as there isn't a duplicate in the array1. Howevever, duckduckgo is a duplicate and will increase the score of duckduckgo.com in array1[7] to 11 and not add it to the array.</p>

<p>Finally, the array should be:</p>

<pre><code>var arrayl = {
 1: {url:google.com, score:1},
 2: {url:bing.com, score: 2},
 3: {url:yahoo.com, score: 0},
 4: {url:facebook.com, score: 5},
 5: {url:dopgile.com, score: 1},
 6: {url:ask.com, score: 10}, 
 7: {url:duckduckgo.com, score: 11}
 8: {url:facebook.com, score: 3}, 
 9: {url:twitter.com, score: 0},
 10: {url:mamma.com, score: 4},
 11: {url:myspace.com, score: 5}
</code></pre>

<p>},</p>

<p>I have tried going through the array with the following loops. </p>

<pre><code>for(var j=0; j&lt;10;j++) {
 for(var k=0; k&lt;10; k++) {
  if(array1[k].url==array2[j].url){

   array1[k].changeRankScore(array1[k].score+1);

  }else{
   //this is the case where it is not the same. Ideally i should just push it to array1    but since it's a double loops, finally all the items will be added from array2 to array1 with several duplicates. 
  }
 }
}
</code></pre>

<p>Help please.</p>
