Skip to content

Instantly share code, notes, and snippets.

@robsonsobral
Forked from ain/Array.prototype.compare.js
Last active July 19, 2017 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robsonsobral/0bb710f713bfc775fb0c19a70f8d57b1 to your computer and use it in GitHub Desktop.
Save robsonsobral/0bb710f713bfc775fb0c19a70f8d57b1 to your computer and use it in GitHub Desktop.
JavaScript compare() method for Array
Array.prototype.compare = function(array) {
if (!array) {
return false;
}
if (this.length !== array.length) {
return false;
}
for (var i = 0, l = this.length; i < l; i++) {
if (this[i] instanceof Array && array[i] instanceof Array) {
if (!this[i].compare(array[i])) {
return false;
}
}
else if (this[i] !== array[i]) {
return false;
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment