Javascript Array equals(array, strict)

Description

Javascript Array equals(array, strict)


Array.prototype.equals = function (array, strict) {
    if (!array)/*from  w w  w .  j  a  v  a 2 s .c  om*/
        return false;

    if (arguments.length == 1)
        strict = true;

    if (this.length != array.length)
        return false;

    for (var i = 0; i < this.length; i++) {
        if (this[i] instanceof Array && array[i] instanceof Array) {
            if (!this[i].equals(array[i], strict))
                return false;
        }
        else if (strict && this[i] != array[i]) {
            return false;
        }
        else if (!strict) {
            return this.sort().equals(array.sort(), true);
        }
    }
    return true;
};



PreviousNext

Related