/* * Copyright 2018 Scytl Secure Electronic Voting SA * * All rights reserved * * See our extended copyright notice in *file 'Copyright.txt' which is part of this source code package */ /* jshint node:true */ 'use strict'; /** * Defines an equality method for Array objects. Only intended for internal use. * * @function equals * @private * @param {Array} * array The Array object that should be checked against this Array * object for equality. * @param {boolean} * [checkOrder=false] If true, checks if the element * order is the same in both Array objects. * @returns {boolean} true if the equality holds, * false otherwise. */ Array.prototype.equals = function(array, checkOrder) { if (!array) { return false; } if (arguments.length === 1) { checkOrder = 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], checkOrder)) { return false; } } else if (checkOrder && (!this[i].equals(array[i]))) { return false; } else if (!checkOrder) { return this.sort().equals(array.sort(), true); } } return true; };