/**
 * Makes the array a have unique elements.
 * WARNING: WILL ALTER THE ARRAY GIVEN
 * @param a
 */
function arrayUnique(a : Array<any>) {
    for(var i=0; i<a.length; ++i) {
        for(var j=i+1; j<a.length; ++j) {
            if(a[i] === a[j])
                a.splice(j--, 1);
        }
    }
    return a;
}

function arrayUniqueNewArray(a : Array<any>) {
    a = a.slice();
    arrayUnique(a);
    return a;
}

function arrayShuffle (a : Array<any>) {
    for (let i = 0; i < a.length; i++) {
        let pos = Math.floor(Math.random() * (a.length - i)) + i;
        let temp = a[i];
        a[i] = a[pos];
        a[pos] = temp;
    }
}

function arrayShuffleNewArray (a : Array<any>) {
    let nA = a.slice();
    arrayShuffle(nA);
    return nA;
}