Skip to content

Instantly share code, notes, and snippets.

@Quby
Created October 6, 2011 16:15
Show Gist options
  • Save Quby/1267826 to your computer and use it in GitHub Desktop.
Save Quby/1267826 to your computer and use it in GitHub Desktop.
function comb (items) {
if (items.length === 1) {
return [items[0]]; //Если только один элемент то только одно сочетание
} else {
var combs = []; //Массив комбинация
for (var i = 0 ; i < items.length ; i++) {
var subCombs = comb(items.slice(0, i).concat(items.slice(i+1))); //Под-сочетания
for (var t = 0 ; t < subCombs.length ; t++) {
combs.push([items[i]].concat(subCombs[t])); //Сочетаем каждое под-сочетание с [items[i]]
}
}
return combs;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment