Created
March 26, 2019 03:47
-
-
Save kiinlam/b6298d6a3d85392c7ed96211673c6199 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 适用于处理二维数组: ([['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