JS全排列

function permutations(string) {
  return string.length === 1
    ? [string]
    : [...new Set([...string].map((item, index) => {
      return permutations(string.slice(0, index) + string.slice(index + 1)).map(val => item + val).join(',');
    }).join(',').split(','))];
}
console.log(permutations("abc"));
console.log(permutations("aabb"));
上一篇:CF285E Positions in Permutations


下一篇:SVN、CVS、VSS区别