Combinations of numbers in array who sum is equal to n
<p>Example:</p>

<pre><code>var a = [1,2,3,4,5,6];
</code></pre>

<p>I want to display all of the unique 3 number combinations in the array where the sum of those 3 digits is equal to 9 (or n).</p>

<p>So result in this example would be:</p>

<pre><code>[1,2,6]
[2,3,4]
[1,3,5]
</code></pre>

<p>Closest thing I could find was permutations of a string...</p>

<pre><code>var alphabet = "abcde"; // shortened to save time

function permute(text) {
if(text.length === 3) { // if length is 3, combination is valid; alert
    console.log(text); // or alert
} else {
    var newalphabet = alphabet.split("").filter(function(v) {
        return text.indexOf(v) === -1;
    }); // construct a new alphabet of characters that are not used yet
        // because each letter may only occur once in each combination

    for(var i = 0; i &lt; newalphabet.length; i++) {
        permute(text + newalphabet[i]); // call permute with current text + new
                                        // letter from filtered alphabet
    }
  }
}

permute("");
</code></pre>