Skip to content

Instantly share code, notes, and snippets.

@brunofurmon
Last active February 1, 2017 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunofurmon/3b4ef241d825c54fc19f99330d3304f0 to your computer and use it in GitHub Desktop.
Save brunofurmon/3b4ef241d825c54fc19f99330d3304f0 to your computer and use it in GitHub Desktop.
// Combination of 2.
// Took about 1 second with an array with 1000 unique ints
var a = [0,1,2];
var combs = [];
var combinationOf2 = function(a)
{
var combs = [];
var size = a.length;
for (i = 0; i < size-1; ++i)
{
for (j = i+1; j < size; ++j)
{
//
combs.push(a[i] + '-' + a[j]);
}
}
return combs
}
// Returns [0-1, 0-2, 1-2]
combinationOf2(a);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment