How do I check for equality between the elements of two arrays without using external libraries (and preferably using ES5)?
I want to check for equality between them without caring about the order of the elements. So the two arrays [1,2,3]
and [2,3,1]
are equal in my situation.
I guess I should write a function
function isEqual(arr1, arr2) {
arr1.forEach(el => {
if (arr2.indexOf(el) === -1) {
return false;
}
});
arr2.forEach(el => {
if (arr1.indexOf(el) === -1) {
return false;
}
});
return true;
}