Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / lodash / internal / baseDifference.js
1 var baseIndexOf = require('./baseIndexOf'),
2     cacheIndexOf = require('./cacheIndexOf'),
3     createCache = require('./createCache');
4
5 /** Used as the size to enable large array optimizations. */
6 var LARGE_ARRAY_SIZE = 200;
7
8 /**
9  * The base implementation of `_.difference` which accepts a single array
10  * of values to exclude.
11  *
12  * @private
13  * @param {Array} array The array to inspect.
14  * @param {Array} values The values to exclude.
15  * @returns {Array} Returns the new array of filtered values.
16  */
17 function baseDifference(array, values) {
18   var length = array ? array.length : 0,
19       result = [];
20
21   if (!length) {
22     return result;
23   }
24   var index = -1,
25       indexOf = baseIndexOf,
26       isCommon = true,
27       cache = (isCommon && values.length >= LARGE_ARRAY_SIZE) ? createCache(values) : null,
28       valuesLength = values.length;
29
30   if (cache) {
31     indexOf = cacheIndexOf;
32     isCommon = false;
33     values = cache;
34   }
35   outer:
36   while (++index < length) {
37     var value = array[index];
38
39     if (isCommon && value === value) {
40       var valuesIndex = valuesLength;
41       while (valuesIndex--) {
42         if (values[valuesIndex] === value) {
43           continue outer;
44         }
45       }
46       result.push(value);
47     }
48     else if (indexOf(values, value, 0) < 0) {
49       result.push(value);
50     }
51   }
52   return result;
53 }
54
55 module.exports = baseDifference;