-
-
Save ipokkel/383a33d7c643e2f64742b926fbd41c7d to your computer and use it in GitHub Desktop.
JavaScript compare() method for Array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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