index.js
958 Bytes
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*!
* arr-diff <https://github.com/jonschlinkert/arr-diff>
*
* Copyright (c) 2014 Jon Schlinkert, contributors.
* Licensed under the MIT License
*/
'use strict';
var flatten = require('arr-flatten');
var slice = [].slice;
/**
* Return the difference between the first array and
* additional arrays.
*
* ```js
* var diff = require('{%= name %}');
*
* var a = ['a', 'b', 'c', 'd'];
* var b = ['b', 'c'];
*
* console.log(diff(a, b))
* //=> ['a', 'd']
* ```
*
* @param {Array} `a`
* @param {Array} `b`
* @return {Array}
* @api public
*/
function diff(arr, arrays) {
var argsLen = arguments.length;
var len = arr.length, i = -1;
var res = [], arrays;
if (argsLen === 1) {
return arr;
}
if (argsLen > 2) {
arrays = flatten(slice.call(arguments, 1));
}
while (++i < len) {
if (!~arrays.indexOf(arr[i])) {
res.push(arr[i]);
}
}
return res;
}
/**
* Expose `diff`
*/
module.exports = diff;