Skip to content

Instantly share code, notes, and snippets.

@kiinlam
Created March 26, 2019 03:47
Show Gist options
  • Save kiinlam/b6298d6a3d85392c7ed96211673c6199 to your computer and use it in GitHub Desktop.
Save kiinlam/b6298d6a3d85392c7ed96211673c6199 to your computer and use it in GitHub Desktop.
// 适用于处理二维数组: ([['a','b'],['c'],['d']],2) --> [[["a","b"],["c"]],[["a","b"],["d"]],[["c"],["d"]]]
function dp_combine(a, m) {
var t = [[]], r = [];
for (var i = 0, n = a.length; i < n; ++i) {
for (var j = 0, l = t.length; j < l; ++j) {
(t[j].length < m - 1 ? t : r).push(t[j].concat([a[i]]));
}
}
return r;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment