title: Javascript - Generating all combinations of elements in a single array (in pairs)
body: <p>I've seen several similar questions about how to generate all possible combinations of elements in an array. But I'm having a very hard time figuring out how to write an algorithm that will only output combination <strong>pairs</strong>. Any suggestions would be super appreciated!</p>
  
  <p>Starting with the following array (with N elements): </p>
  
  <pre><code>var array = ["apple", "banana", "lemon", "mango"];
  </code></pre>
  
  <p>And getting the following result:</p>
  
  <pre><code>var result = [
     "apple banana"
     "apple lemon"
     "apple mango"
     "banana lemon"
     "banana mango"
     "lemon mango"
  ];
  </code></pre>
  
  <p>I was trying out the following approach but this results in all possible combinations, instead only combination pairs.</p>
  
  <pre><code>var letters = splSentences;
  var combi = [];
  var temp= "";
  var letLen = Math.pow(2, letters.length);
  
  for (var i = 0; i &lt; letLen ; i++){
      temp= "";
      for (var j=0;j&lt;letters.length;j++) {
          if ((i &amp; Math.pow(2,j))){ 
              temp += letters[j]+ " "
          }
      }
      if (temp !== "") {
          combi.push(temp);
      }
  }
  </code></pre>