JavaScript 数组全排列算法:输出子数组结果
const permute = (arr) => arr.length === 1 ? [arr] : arr.flatMap((val, i) => {\n const subPermutations = permute([...arr.slice(0, i), ...arr.slice(i + 1)]);\n return subPermutations.map((perm) => [val, ...perm, ...subPermutations]);\n});
原文地址: https://www.cveoy.top/t/topic/pEaC 著作权归作者所有。请勿转载和采集!