Projekt

Obecné

Profil

Stáhnout (805 Bajtů) Statistiky
| Větev: | Revize:
1
/*!
2
 * arr-diff <https://github.com/jonschlinkert/arr-diff>
3
 *
4
 * Copyright (c) 2014-2017, Jon Schlinkert.
5
 * Released under the MIT License.
6
 */
7

    
8
'use strict';
9

    
10
module.exports = function diff(arr/*, arrays*/) {
11
  var len = arguments.length;
12
  var idx = 0;
13
  while (++idx < len) {
14
    arr = diffArray(arr, arguments[idx]);
15
  }
16
  return arr;
17
};
18

    
19
function diffArray(one, two) {
20
  if (!Array.isArray(two)) {
21
    return one.slice();
22
  }
23

    
24
  var tlen = two.length
25
  var olen = one.length;
26
  var idx = -1;
27
  var arr = [];
28

    
29
  while (++idx < olen) {
30
    var ele = one[idx];
31

    
32
    var hasEle = false;
33
    for (var i = 0; i < tlen; i++) {
34
      var val = two[i];
35

    
36
      if (ele === val) {
37
        hasEle = true;
38
        break;
39
      }
40
    }
41

    
42
    if (hasEle === false) {
43
      arr.push(ele);
44
    }
45
  }
46
  return arr;
47
}
(3-3/4)