public
Created

utility function to compare 2 arrays deeply

  • Download Gist
gistfile1.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// 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;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.