exchange(str, i, j){ let arr = str.split("") if(str == ""){ return }else { let tmp = arr[i] arr[i] = arr[j] arr[j] = tmp } this.str = arr.join("") // console.log("str", this.str) }, fullPermutationsOfString(str, begin, end){ str = this.str if(str == "" || begin > end){ return } if(begin == end - 1){ console.log(str) }else { for(let i = begin; i < end; ++i){ this.exchange(str, begin, i) this.fullPermutationsOfString(str, begin+1, end) this.exchange(str, begin, i) } } }
this.str = "ab" let length = this.str.length this.fullPermutationsOfString(this.str, 0, length)