fix
This commit is contained in:
46
book/node_modules/array-difference/difference.js
generated
vendored
Normal file
46
book/node_modules/array-difference/difference.js
generated
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
(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));
|
Reference in New Issue
Block a user