Created
September 17, 2019 07:40
-
-
Save mytharcher/a8aedc8ca066937cf5316b7178a0acb1 to your computer and use it in GitHub Desktop.
计算任意多个维度有限元素生成的所有向量组合
This file contains 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
const lists = [ | |
[1, 2], | |
[3, 4], | |
[5], | |
[7] | |
]; | |
const combinations = lists | |
.reduce((all, current) => current | |
.map(item => all.map(g => g.concat([item]))) | |
.reduce((prev, curr) => prev.concat(curr), []) | |
, [[]]); | |
console.log(combinations); | |
/* | |
[ | |
[ 1, 3, 5, 7 ], | |
[ 2, 3, 5, 7 ], | |
[ 1, 4, 5, 7 ], | |
[ 2, 4, 5, 7 ] | |
] | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment