jcanfield
10/4/2012 - 6:42 PM

jQuery Array Compare

jQuery Array Compare

/**
 * Compare two arrays if the are equal even if the have different order.
 *
 * @link http://stackoverflow.com/a/7726509
 */
jQuery.extend({
  /**
   * @param {array} a
   *   First array to compare.
   * @param {array} b
   *   Second array to compare.
   * @return {boolean}
   *   True if both arrays are equal, otherwise false.
   */
  arrayCompare: function (a, b) {
    return $(a).not(b).get().length === 0 && $(b).not(a).get().length === 0;
  }
});