After stealing this JavaScript combination generator, I added a parameter to supply the minimum length resulting in,
var combine = function(a, min) {
var fn = function(n, src, got, all) {
if (n == 0) {
if (got.length > 0) {
all[all.length] = got;
}
return;
}
for (var j = 0; j < src.length; j++) {
fn(n - 1, src.slice(j + 1), got.concat([src[j]]), all);
}
return;
}
var all = [];
for (var i = min; i < a.length; i++) {
fn(i, a, [], all);
}
all.push(a);
return all;
}
To use, supply an array, and the minimum subset length desired,
var subsets = combine([1, 2, 3], 2);
Output is,
[[1, 2], [1, 3], [2, 3], [1, 2, 3]]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…