代码
提交代码
function getGroup(data, index = 0, group = []) {//生成全排列 var need_apply = new Array(); need_apply.push(data[index]); for(var i = 0; i < group.length; i++) { need_apply.push(group[i] + data[index]); } group.push.apply(group, need_apply); if(index + 1 >= data.length) return group; else return getGroup(data, index + 1, group); } onmessage = function(message){//监听主线程的数据请求 var msg = message.data; if(msg == "") postMessage("请输入正确的字符串"); else { var data = msg.split("");//将字符串转数组 postMessage(getGroup(data)); } }
运行结果