| /** |
| * Lo-Dash 2.4.1 (Custom Build) <http://lodash.com/> |
| * Build: `lodash modularize exports="node" -o ./compat/` |
| * Copyright 2012-2013 The Dojo Foundation <http://dojofoundation.org/> |
| * Based on Underscore.js 1.5.2 <http://underscorejs.org/LICENSE> |
| * Copyright 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors |
| * Available under MIT license <http://lodash.com/license> |
| */ |
| var baseIndexOf = require('./baseIndexOf'), |
| cacheIndexOf = require('./cacheIndexOf'), |
| createCache = require('./createCache'), |
| largeArraySize = require('./largeArraySize'), |
| releaseObject = require('./releaseObject'); |
| |
| /** |
| * The base implementation of `_.difference` that accepts a single array |
| * of values to exclude. |
| * |
| * @private |
| * @param {Array} array The array to process. |
| * @param {Array} [values] The array of values to exclude. |
| * @returns {Array} Returns a new array of filtered values. |
| */ |
| function baseDifference(array, values) { |
| var index = -1, |
| indexOf = baseIndexOf, |
| length = array ? array.length : 0, |
| isLarge = length >= largeArraySize, |
| result = []; |
| |
| if (isLarge) { |
| var cache = createCache(values); |
| if (cache) { |
| indexOf = cacheIndexOf; |
| values = cache; |
| } else { |
| isLarge = false; |
| } |
| } |
| while (++index < length) { |
| var value = array[index]; |
| if (indexOf(values, value) < 0) { |
| result.push(value); |
| } |
| } |
| if (isLarge) { |
| releaseObject(values); |
| } |
| return result; |
| } |
| |
| module.exports = baseDifference; |