Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / lodash / internal / baseUniq.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 `_.uniq` without support for callback shorthands
10  * and `this` binding.
11  *
12  * @private
13  * @param {Array} array The array to inspect.
14  * @param {Function} [iteratee] The function invoked per iteration.
15  * @returns {Array} Returns the new duplicate free array.
16  */
17 function baseUniq(array, iteratee) {
18   var index = -1,
19       indexOf = baseIndexOf,
20       length = array.length,
21       isCommon = true,
22       isLarge = isCommon && length >= LARGE_ARRAY_SIZE,
23       seen = isLarge ? createCache() : null,
24       result = [];
25
26   if (seen) {
27     indexOf = cacheIndexOf;
28     isCommon = false;
29   } else {
30     isLarge = false;
31     seen = iteratee ? [] : result;
32   }
33   outer:
34   while (++index < length) {
35     var value = array[index],
36         computed = iteratee ? iteratee(value, index, array) : value;
37
38     if (isCommon && value === value) {
39       var seenIndex = seen.length;
40       while (seenIndex--) {
41         if (seen[seenIndex] === computed) {
42           continue outer;
43         }
44       }
45       if (iteratee) {
46         seen.push(computed);
47       }
48       result.push(value);
49     }
50     else if (indexOf(seen, computed, 0) < 0) {
51       if (iteratee || isLarge) {
52         seen.push(computed);
53       }
54       result.push(value);
55     }
56   }
57   return result;
58 }
59
60 module.exports = baseUniq;