class Permutation {
constructor (arr) {
this.arr = Array.from(arr);
this.length = 0;
this.result = []
this.run(0)
}
run (index) {
if (index === this.arr.length - 1) {
this.result.push(Array.from(this.arr))
this.length ++
return
}
for (let i = index; i < this.arr.length; i++) {
let arr = this.arr;
[arr[index], arr[i]] = [arr[i], arr[index]];
this.run(index + 1);
[arr[index], arr[i]] = [arr[i], arr[index]];
}
}
}
let p = new Permutation(['a', 'b', 'c', 'd']);
p.result.forEach(el => {
console.log(el, '\n')
})
console.log(p.length);
console