function difference(a, b) {
b.length > a.length && ([b,a] = [a,b]);
return a.filter(function(a) {
return b.indexOf(a) == -1;
});
}
var a = [1,2,3,4,5,6,7], b = [5,3,2,1];
alert(difference(a, b)); //[ 4, 6, 7 ]
alert(difference(b, a)); //[ 4, 6, 7 ]
Вариант.