SOURCE

const data = [1, 2, 2];
function swap(array, one, two) {
    const temp = array[one];
    array[one] = array[two];
    array[two] = temp;
}

function AcceptSwap(array, start, end) {
    for (let i = start;i < end;i++) {
        if (array[i] === array[end]) {
            return false;
        }
    }
    return true;
}

function AllArrange(array) {
    const length = array.length;
    _AllArrange(array, 0, length - 1);
}

function _AllArrange(array, start, end) {
    if (start === end) {
        console.log(array);
        return;
    }
    for (let i = start;i <= end;i++) {
        if (!AcceptSwap(array, start, i)) {
            continue;
        }
        swap(array, start, i);
        _AllArrange(array, start + 1, end);
        swap(array, start, i);
    }
}

AllArrange(data);

console 命令行工具 X clear

                    
>
console