Skip to content

Instantly share code, notes, and snippets.

@olalonde
Created March 2, 2012 01:43
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 olalonde/1954722 to your computer and use it in GitHub Desktop.
Save olalonde/1954722 to your computer and use it in GitHub Desktop.
utility function to compare 2 arrays deeply
// utility function, returns true if arr1 is equal to arr2
function arrays_are_equivalent(arr1, arr2, ret) {
if(ret === undefined) ret = true;
if(arr1.length != arr2.length) return false;
arr1.forEach(function(ele, i) {
if(ele instanceof Array) {
ret = ret && arrays_are_equivalent(ele, arr2[i]);
}
else if(ele !== arr2[i]) {
ret = false;
return;
}
});
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment