array difference

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function arrayDiff(){
var args = arguments, strict = false, d = 0;
if (typeof args[0] == 'boolean' && args[0])
strict = true, d = 1;
var len = args.length - d;
if (len < 2)
return false;
else if (len > 2) {
var i = d, test = args[d];
while ((++i < len) && arrayDiff(strict, args[i], test))
;
return i == len;
} else {
var a = args[d], b = args[d + 1], tmp = [];
var len1 = a.length, len2 = b.length, i = -1, j = -1;
if (len1 != len2)
return false;
while (++i < len1) {
var x = a[i], t = typeof x, key = strict ? i + t + x : t + x;
if (t != 'undefined')
tmp[key] = x;
}
while (++j < len2) {
var x = b[j], t = typeof x, key = strict ? j + t + x : t + x;
if (t != 'undefined') {
if (!tmp[key])
return false;
else if (t == 'object' && !arrayDiff(strict, x, tmp[key]))
return false;
}
}
return true;
}
}