const _permute = (string) => { // 补全代码 let res = []; let arr = string.split(""); while (true) { // 数组随机乱序后的字符串 let str = arr.sort((a, b) => Math.random() - 0.5).join(""); // 如果生成的字符串不在res数组中加入 if (!res.includes(str)) res.push(str); // 结果数组长度和源字符串的2倍长度相等为循环终止条件 if (res.length === string.length * 2) break; } return res; }; console.log(_permute("abc"));