I am trying to write an asynchronous array strict equal function that reports errors how I want it to.
Here's my function:
ArrayStrictEqual = function (arr1, arr2, callback) {
var arr2s = arr2.sort();
var eq = true;
try {
arr1.sort().forEach(function (item, index, array) {
if(!(_.isEqual(arr2s[index], item))) {
throw new Error(arr1 + " is not strictly equal to " + arr2);
}
});
}
catch (err) {
if (err) eq = false;
}
finally {
callback(err, eq);
}
};
But, when I run this, it says, Uncaught ReferenceError: err is not defined
.
I was going to initialize err to null before the try-catch. But this doesn't seem like the right thing to do. But, I'm not sure what the right thing to do is. Should I be going about this in a completely different way (i.e. not try-catch)?