javascript - js给出所有组合
本文介绍了javascript - js给出所有组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
如何得出多有组合?
用js
有好的思路指点一下吗~
解决方案
考来的。。。
function permute(input) {
var permArr = [],
usedChars = [];
function main(input){
var i, ch;
for (i = 0; i < input.length; i++) {
ch = input.splice(i, 1)[0];
usedChars.push(ch);
if (input.length == 0) {
permArr.push(usedChars.slice());
}
main(input);
input.splice(i, 0, ch);
usedChars.pop();
}
return permArr;
}
return main(input).join('\n');
};
console.log(permute(['foo','bar','hello','world']));
这篇关于javascript - js给出所有组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文