We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
有这么几个变量:
实现一个函数 getArranging 可以返回它们的可能值的排列组合二维数组:
function getArranging( ){ //TODO - 返回参数的排列组合 } var a = [0, 1]; var b = [3, 4, 5]; var c = [6, 7]; var ret = getArranging( a, b, c ); // ret 值为: /** [ [0,3,6], [0,3,7], [0,4,6], [0,4,7], [0,5,6], [0,5,7], [1,3,6], [1,3,7], [1,4,6], [1,4,7], [1,5,6], [1,5,7] ] **/
The text was updated successfully, but these errors were encountered:
/** [1, 2] [3, 4, 5] [6, 7, 8] */ function gen (...xss) { const len = xss.length const ret = [] if (len === 0) { return ret } function genCore (acc, xssIndex) { const xs = xss[xssIndex] if (xs.length !== 0) { xs.forEach((x, i) => { const newAcc = [...acc, x] if (xssIndex + 1 === len) { ret.push(newAcc) return } genCore(newAcc, xssIndex + 1) }) return } genCore(acc, xssIndex + 1) } genCore([], 0) return ret } function test (...xs) { console.time('gen') const ret = gen(...xs) console.timeEnd('gen') return ret } test([1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [6, 7, 8, 9, 10])
爽不爽
Sorry, something went wrong.
function cartesian (...lists) { return lists .map(list => list.map(item => [item])) .reduce((listsA, listsB) => listsA.reduce((list, listA) => list.concat( listsB.map(listB => listA.concat(listB)) ), [] ) ) }
No branches or pull requests
有这么几个变量:
实现一个函数 getArranging 可以返回它们的可能值的排列组合二维数组:
The text was updated successfully, but these errors were encountered: