Skip to content

Instantly share code, notes, and snippets.

@Ynote
Last active June 14, 2016 16:46
Show Gist options
  • Save Ynote/89bce18458b2f71f687b to your computer and use it in GitHub Desktop.
Save Ynote/89bce18458b2f71f687b to your computer and use it in GitHub Desktop.
[Javascript] - Pairwise combinations of an array
var pairwise = function(arr)
{
if (arr.length < 2){ return []; }
var first = arr[0],
sliced = arr.slice(1),
getPair = function(x){ return [first, x]; }
pairs = sliced.map(getPair);
return pairs.concat(createPossibilities(sliced));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment