title: Getting the number of mutual friends using Facebook Graph API
body: <p>So I use the code below to get the users friends first, and then use the users friends IDs to generate the number of mutual friends that they have. Clearly iterating through all the friends and comparing it each time is a lengthy process but it works. However, the page takes a while to load. How do I reduce the time it takes or optimize the following code?</p>
  
  <pre><code>    function getFriends() 
  
      {
        FB.api('/me/friends', function(response) {
        friendCount = response.data.length;
        $("h2").append(friendCount+ ' friends');
        if(response.data) {
          $.each(response.data,function(index,friend) {
              FB.api('/me/mutualfriends/'+friend.id, function(mutualfriends) {
              $("#results").append('&lt;ul&gt;&lt;li&gt;' + friend.name + ' has id:' + friend.id + ' has mutual friends: ' + mutualfriends.data.length + '&lt;/li&gt;&lt;/ul&gt;');
              $("#results").append('&lt;img src="http://graph.facebook.com/' + friend.id + '/picture" /&gt;');
              });
  
          });
      } else {
          console.log("Error!");
      }
      });
      }
  </code></pre>