Sha256: 21bf6502bd0fd64f2bbe11eedd9b17e2e93440220f4a044e80b20fc507221812

Contents?: true

Size: 1.87 KB

Versions: 273

Compression:

Stored size: 1.87 KB

Contents

var SetCache = require('./_SetCache'),
    arrayIncludes = require('./_arrayIncludes'),
    arrayIncludesWith = require('./_arrayIncludesWith'),
    arrayMap = require('./_arrayMap'),
    baseUnary = require('./_baseUnary'),
    cacheHas = require('./_cacheHas');

/** Used as the size to enable large array optimizations. */
var LARGE_ARRAY_SIZE = 200;

/**
 * The base implementation of methods like `_.difference` without support
 * for excluding multiple arrays or iteratee shorthands.
 *
 * @private
 * @param {Array} array The array to inspect.
 * @param {Array} values The values to exclude.
 * @param {Function} [iteratee] The iteratee invoked per element.
 * @param {Function} [comparator] The comparator invoked per element.
 * @returns {Array} Returns the new array of filtered values.
 */
function baseDifference(array, values, iteratee, comparator) {
  var index = -1,
      includes = arrayIncludes,
      isCommon = true,
      length = array.length,
      result = [],
      valuesLength = values.length;

  if (!length) {
    return result;
  }
  if (iteratee) {
    values = arrayMap(values, baseUnary(iteratee));
  }
  if (comparator) {
    includes = arrayIncludesWith;
    isCommon = false;
  }
  else if (values.length >= LARGE_ARRAY_SIZE) {
    includes = cacheHas;
    isCommon = false;
    values = new SetCache(values);
  }
  outer:
  while (++index < length) {
    var value = array[index],
        computed = iteratee == null ? value : iteratee(value);

    value = (comparator || value !== 0) ? value : 0;
    if (isCommon && computed === computed) {
      var valuesIndex = valuesLength;
      while (valuesIndex--) {
        if (values[valuesIndex] === computed) {
          continue outer;
        }
      }
      result.push(value);
    }
    else if (!includes(values, computed, comparator)) {
      result.push(value);
    }
  }
  return result;
}

module.exports = baseDifference;

Version data entries

273 entries across 271 versions & 29 rubygems

Version Path
immosquare-cleaner-0.1.60 node_modules/lodash/_baseDifference.js
immosquare-cleaner-0.1.59 node_modules/lodash/_baseDifference.js
immosquare-cleaner-0.1.58 node_modules/lodash/_baseDifference.js
immosquare-cleaner-0.1.57 node_modules/lodash/_baseDifference.js
immosquare-cleaner-0.1.56 node_modules/lodash/_baseDifference.js
immosquare-cleaner-0.1.55 node_modules/lodash/_baseDifference.js
immosquare-cleaner-0.1.54 node_modules/lodash/_baseDifference.js
immosquare-cleaner-0.1.53 node_modules/lodash/_baseDifference.js
immosquare-cleaner-0.1.52 node_modules/lodash/_baseDifference.js
trusty-cms-6.3.1 node_modules/lodash/_baseDifference.js
immosquare-cleaner-0.1.51 node_modules/lodash/_baseDifference.js
boring_generators-0.15.0 tmp/templates/app_template/node_modules/lodash/_baseDifference.js
clapton-0.0.26 lib/clapton/javascripts/node_modules/lodash/_baseDifference.js
clapton-0.0.25 lib/clapton/javascripts/node_modules/lodash/_baseDifference.js
immosquare-cleaner-0.1.50 node_modules/lodash/_baseDifference.js
clapton-0.0.24 lib/clapton/javascripts/node_modules/lodash/_baseDifference.js
clapton-0.0.23 lib/clapton/javascripts/node_modules/lodash/_baseDifference.js
clapton-0.0.22 lib/clapton/javascripts/node_modules/lodash/_baseDifference.js
clapton-0.0.21 lib/clapton/javascripts/node_modules/lodash/_baseDifference.js
clapton-0.0.20 lib/clapton/javascripts/node_modules/lodash/_baseDifference.js