2025-05-12 05:38:44 +09:00

47 lines
893 B
JavaScript

(function(global) {
var indexOf = Array.prototype.indexOf || function(elem) {
var idx, len;
if (this == null) {
throw new TypeError("indexOf called on null or undefined");
}
for (idx = 0, len = this.length; idx < len; ++idx) {
if (this[idx] === elem) {
return idx;
}
}
return -1;
};
function difference(a, b) {
var idx, len;
var res = [];
for (idx = 0, len = a.length; idx < len; ++idx) {
if (indexOf.call(b, a[idx]) === -1) {
res.push(a[idx]);
}
}
for (idx = 0, len = b.length; idx < len; ++idx) {
if (indexOf.call(a, b[idx]) === -1) {
res.push(b[idx]);
}
}
return res;
}
if (typeof module === "object" && module.exports) {
module.exports = difference;
} else if (typeof define === "function" && define.amd) {
define(function() {
return difference;
});
} else {
global.difference = difference;
}
}(this));