Here is my version
function diff(arr1, arr2) {
var obj = {}, matched = [],
unmatched = [];
for (var i = 0, l = arr1.length; i < l; i++) {
obj[arr1[i]] = (obj[arr1[i]] || 0) + 1;
}
for (i = 0; i < arr2.length; i++) {
var val = arr2[i];
if (val in obj) {
matched.push(val);
} else {
unmatched.push(val);
}
}
// Here you can find how many times an element is repeating.
console.log(obj);
// Here you can find what are matching.
console.log(matched);
// Here you can check whether they are equal or not.
console.log('Both are equal ? :' +
matched.length === a.length);
// Here you can find what are different
console.log(unmatched);
}