Compare commits

...

6 Commits

Author SHA1 Message Date
jdalton
10d5566cf2 Bump to v3.9.3. 2015-05-25 20:56:15 -07:00
jdalton
314048b069 Bump to v3.9.2. 2015-05-24 01:44:03 -07:00
jdalton
b6f9660ab0 Bump to v3.9.1. 2015-05-19 13:50:30 -07:00
jdalton
f84f83a4a5 Bump to v3.9.0. 2015-05-19 13:46:23 -07:00
jdalton
53c14e5b9b Bump to v3.8.0. 2015-05-01 08:25:59 -07:00
jdalton
863bb301bb Bump to v3.7.0. 2015-04-16 08:01:14 -07:00
194 changed files with 2968 additions and 1988 deletions

View File

@@ -1,4 +1,4 @@
# lodash v3.6.0
# lodash v3.9.3
The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash](https://lodash.com/) exported as [Node.js](http://nodejs.org/)/[io.js](https://iojs.org/) modules.
@@ -28,7 +28,7 @@ var array = require('lodash/array');
var chunk = require('lodash/array/chunk');
```
See the [package source](https://github.com/lodash/lodash/tree/3.6.0-npm) for more details.
See the [package source](https://github.com/lodash/lodash/tree/3.9.3-npm) for more details.
**Note:**<br>
Dont assign values to the [special variable](http://nodejs.org/api/repl.html#repl_repl_features) `_` when in the REPL.<br>
@@ -39,15 +39,14 @@ Install [n_](https://www.npmjs.com/package/n_) for a REPL that includes lodash b
lodash is also available in a variety of other builds & module formats.
* npm packages for [modern](https://www.npmjs.com/package/lodash), [compatibility](https://www.npmjs.com/package/lodash-compat), & [per method](https://www.npmjs.com/browse/keyword/lodash-modularized) builds
* AMD modules for [modern](https://github.com/lodash/lodash/tree/3.6.0-amd) & [compatibility](https://github.com/lodash/lodash-compat/tree/3.6.0-amd) builds
* ES modules for the [modern](https://github.com/lodash/lodash/tree/3.6.0-es) build
* AMD modules for [modern](https://github.com/lodash/lodash/tree/3.9.3-amd) & [compatibility](https://github.com/lodash/lodash-compat/tree/3.9.3-amd) builds
* ES modules for the [modern](https://github.com/lodash/lodash/tree/3.9.3-es) build
## Further Reading
* [API Documentation](https://lodash.com/docs)
* [Build Differences](https://github.com/lodash/lodash/wiki/Build-Differences)
* [Changelog](https://github.com/lodash/lodash/wiki/Changelog)
* [Release Notes](https://github.com/lodash/lodash/releases)
* [Roadmap](https://github.com/lodash/lodash/wiki/Roadmap)
* [More Resources](https://github.com/lodash/lodash/wiki/Resources)
@@ -66,7 +65,6 @@ lodash is also available in a variety of other builds & module formats.
* [_.chunk](https://lodash.com/docs#chunk) for splitting an array into chunks of a given size
* [_.clone](https://lodash.com/docs#clone) supports shallow cloning of `Date` & `RegExp` objects
* [_.cloneDeep](https://lodash.com/docs#cloneDeep) for deep cloning arrays & objects
* [_.create](https://lodash.com/docs#create) for easier object inheritance
* [_.curry](https://lodash.com/docs#curry) & [_.curryRight](https://lodash.com/docs#curryRight) for creating [curried](http://hughfdjackson.com/javascript/why-curry-helps/) functions
* [_.debounce](https://lodash.com/docs#debounce) & [_.throttle](https://lodash.com/docs#throttle) are cancelable & accept options for more control
* [_.fill](https://lodash.com/docs#fill) to fill arrays with values
@@ -75,12 +73,16 @@ lodash is also available in a variety of other builds & module formats.
* [_.forEach](https://lodash.com/docs#forEach) supports exiting early
* [_.forIn](https://lodash.com/docs#forIn) for iterating all enumerable properties
* [_.forOwn](https://lodash.com/docs#forOwn) for iterating own properties
* [_.get](https://lodash.com/docs#get) & [_.set](https://lodash.com/docs#set) for deep property getting & setting
* [_.gt](https://lodash.com/docs#gt), [_.gte](https://lodash.com/docs#gte), [_.lt](https://lodash.com/docs#lt), & [_.lte](https://lodash.com/docs#lte) relational methods
* [_.inRange](https://lodash.com/docs#inRange) for checking whether a number is within a given range
* [_.isNative](https://lodash.com/docs#isNative) to check for native functions
* [_.isPlainObject](https://lodash.com/docs#isPlainObject) & [_.toPlainObject](https://lodash.com/docs#toPlainObject) to check for & convert to `Object` objects
* [_.isTypedArray](https://lodash.com/docs#isTypedArray) to check for typed arrays
* [_.mapKeys](https://lodash.com/docs#mapKeys) for mapping keys to an object
* [_.matches](https://lodash.com/docs#matches) supports deep object comparisons
* [_.matchesProperty](https://lodash.com/docs#matchesProperty) to complement [_.matches](https://lodash.com/docs#matches) & [_.property](https://lodash.com/docs#property)
* [_.method](https://lodash.com/docs#method) & [_.methodOf](https://lodash.com/docs#methodOf) to create functions that invoke methods
* [_.merge](https://lodash.com/docs#merge) for a deep [_.extend](https://lodash.com/docs#extend)
* [_.parseInt](https://lodash.com/docs#parseInt) for consistent cross-environment behavior
* [_.pull](https://lodash.com/docs#pull), [_.pullAt](https://lodash.com/docs#pullAt), & [_.remove](https://lodash.com/docs#remove) for mutating arrays
@@ -93,6 +95,7 @@ lodash is also available in a variety of other builds & module formats.
* [_.support](https://lodash.com/docs#support) for flagging environment features
* [_.template](https://lodash.com/docs#template) supports [*“imports”*](https://lodash.com/docs#templateSettings-imports) options & [ES template delimiters](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-template-literal-lexical-components)
* [_.transform](https://lodash.com/docs#transform) as a powerful alternative to [_.reduce](https://lodash.com/docs#reduce) for transforming objects
* [_.unzipWith](https://lodash.com/docs#unzipWith) & [_.zipWith](https://lodash.com/docs#zipWith) to specify how grouped values should be combined
* [_.xor](https://lodash.com/docs#xor) to complement [_.difference](https://lodash.com/docs#difference), [_.intersection](https://lodash.com/docs#intersection), & [_.union](https://lodash.com/docs#union)
* [_.valuesIn](https://lodash.com/docs#valuesIn) for getting values of all enumerable properties
* [_.bind](https://lodash.com/docs#bind), [_.curry](https://lodash.com/docs#curry), [_.partial](https://lodash.com/docs#partial), &
@@ -100,17 +103,17 @@ lodash is also available in a variety of other builds & module formats.
* [_.capitalize](https://lodash.com/docs#capitalize), [_.trim](https://lodash.com/docs#trim), &
[more](https://lodash.com/docs "_.camelCase, _.deburr, _.endsWith, _.escapeRegExp, _.kebabCase, _.pad, _.padLeft, _.padRight, _.repeat, _.snakeCase, _.startCase, _.startsWith, _.trimLeft, _.trimRight, _.trunc, _.words") string methods
* [_.clone](https://lodash.com/docs#clone), [_.isEqual](https://lodash.com/docs#isEqual), &
[more](https://lodash.com/docs "_.assign, _.cloneDeep, _.merge") accept callbacks
[more](https://lodash.com/docs "_.assign, _.cloneDeep, _.merge") accept customizer callbacks
* [_.dropWhile](https://lodash.com/docs#dropWhile), [_.takeWhile](https://lodash.com/docs#takeWhile), &
[more](https://lodash.com/docs "_.drop, _.dropRightWhile, _.take, _.takeRightWhile") to complement [_.first](https://lodash.com/docs#first), [_.initial](https://lodash.com/docs#initial), [_.last](https://lodash.com/docs#last), & [_.rest](https://lodash.com/docs#rest)
[more](https://lodash.com/docs "_.drop, _.dropRight, _.dropRightWhile, _.take, _.takeRight, _.takeRightWhile") to complement [_.first](https://lodash.com/docs#first), [_.initial](https://lodash.com/docs#initial), [_.last](https://lodash.com/docs#last), & [_.rest](https://lodash.com/docs#rest)
* [_.findLast](https://lodash.com/docs#findLast), [_.findLastKey](https://lodash.com/docs#findLastKey), &
[more](https://lodash.com/docs "_.flowRight, _.forEachRight, _.forInRight, _.forOwnRight, _.partialRight") right-associative methods
[more](https://lodash.com/docs "_.curryRight, _.dropRight, _.dropRightWhile, _.flowRight, _.forEachRight, _.forInRight, _.forOwnRight, _.padRight, partialRight, _.takeRight, _.trimRight, _.takeRightWhile") right-associative methods
* [_.includes](https://lodash.com/docs#includes), [_.toArray](https://lodash.com/docs#toArray), &
[more](https://lodash.com/docs "_.at, _.countBy, _.every, _.filter, _.find, _.findLast, _.forEach, _.forEachRight, _.groupBy, _.indexBy, _.invoke, _.map, _.max, _.min, _.partition, _.pluck, _.reduce, _.reduceRight, _.reject, _.shuffle, _.size, _.some, _.sortBy") accept strings
[more](https://lodash.com/docs "_.at, _.countBy, _.every, _.filter, _.find, _.findLast, _.findWhere, _.forEach, _.forEachRight, _.groupBy, _.indexBy, _.invoke, _.map, _.max, _.min, _.partition, _.pluck, _.reduce, _.reduceRight, _.reject, _.shuffle, _.size, _.some, _.sortBy, _.sortByAll, _.sortByOrder, _.sum, _.where") accept strings
* [_#commit](https://lodash.com/docs#prototype-commit) & [_#plant](https://lodash.com/docs#prototype-plant) for working with chain sequences
* [_#thru](https://lodash.com/docs#thru) to pass values thru a chain sequence
## Support
Tested in Chrome 40-41, Firefox 35-36, IE 6-11, Opera 27-28, Safari 5-8, io.js 1.6.2, Node.js 0.8.28, 0.10.36, & 0.12.0, PhantomJS 1.9.8, RingoJS 0.11, & Rhino 1.7RC5.
Tested in Chrome 41-42, Firefox 37-38, IE 6-11, MS Edge, Opera 28-29, Safari 5-8, ChakraNode 0.12.2, io.js 2.1.0, Node.js 0.8.28, 0.10.38, & 0.12.4, PhantomJS 1.9.8, RingoJS 0.11, & Rhino 1.7.6.
Automated [browser](https://saucelabs.com/u/lodash) & [CI](https://travis-ci.org/lodash/lodash/) test runs are available. Special thanks to [Sauce Labs](https://saucelabs.com/) for providing automated browser testing.

View File

@@ -35,8 +35,10 @@ module.exports = {
'uniq': require('./array/uniq'),
'unique': require('./array/unique'),
'unzip': require('./array/unzip'),
'unzipWith': require('./array/unzipWith'),
'without': require('./array/without'),
'xor': require('./array/xor'),
'zip': require('./array/zip'),
'zipObject': require('./array/zipObject')
'zipObject': require('./array/zipObject'),
'zipWith': require('./array/zipWith')
};

View File

@@ -1,16 +1,12 @@
var baseDifference = require('../internal/baseDifference'),
baseFlatten = require('../internal/baseFlatten'),
isArguments = require('../lang/isArguments'),
isArray = require('../lang/isArray'),
isArrayLike = require('../internal/isArrayLike'),
restParam = require('../function/restParam');
/**
* Creates an array excluding all values of the provided arrays using
* `SameValueZero` for equality comparisons.
*
* **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* comparisons are like strict equality comparisons, e.g. `===`, except that
* `NaN` matches `NaN`.
* Creates an array of unique `array` values not included in the other
* provided arrays using [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* for equality comparisons.
*
* @static
* @memberOf _
@@ -24,7 +20,7 @@ var baseDifference = require('../internal/baseDifference'),
* // => [1, 3]
*/
var difference = restParam(function(array, values) {
return (isArray(array) || isArguments(array))
return isArrayLike(array)
? baseDifference(array, baseFlatten(values, false, true))
: [];
});

View File

@@ -6,13 +6,10 @@ var nativeMax = Math.max;
/**
* Gets the index at which the first occurrence of `value` is found in `array`
* using `SameValueZero` for equality comparisons. If `fromIndex` is negative,
* it is used as the offset from the end of `array`. If `array` is sorted
* providing `true` for `fromIndex` performs a faster binary search.
*
* **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* comparisons are like strict equality comparisons, e.g. `===`, except that
* `NaN` matches `NaN`.
* using [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* for equality comparisons. If `fromIndex` is negative, it is used as the offset
* from the end of `array`. If `array` is sorted providing `true` for `fromIndex`
* performs a faster binary search.
*
* @static
* @memberOf _

View File

@@ -1,17 +1,14 @@
var baseIndexOf = require('../internal/baseIndexOf'),
cacheIndexOf = require('../internal/cacheIndexOf'),
createCache = require('../internal/createCache'),
isArguments = require('../lang/isArguments'),
isArray = require('../lang/isArray');
isArrayLike = require('../internal/isArrayLike'),
restParam = require('../function/restParam');
/**
* Creates an array of unique values in all provided arrays using `SameValueZero`
* Creates an array of unique values that are included in all of the provided
* arrays using [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* for equality comparisons.
*
* **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* comparisons are like strict equality comparisons, e.g. `===`, except that
* `NaN` matches `NaN`.
*
* @static
* @memberOf _
* @category Array
@@ -21,36 +18,31 @@ var baseIndexOf = require('../internal/baseIndexOf'),
* _.intersection([1, 2], [4, 2], [2, 1]);
* // => [2]
*/
function intersection() {
var args = [],
argsIndex = -1,
argsLength = arguments.length,
caches = [],
var intersection = restParam(function(arrays) {
var othLength = arrays.length,
othIndex = othLength,
caches = Array(length),
indexOf = baseIndexOf,
isCommon = true;
isCommon = true,
result = [];
while (++argsIndex < argsLength) {
var value = arguments[argsIndex];
if (isArray(value) || isArguments(value)) {
args.push(value);
caches.push((isCommon && value.length >= 120) ? createCache(argsIndex && value) : null);
}
while (othIndex--) {
var value = arrays[othIndex] = isArrayLike(value = arrays[othIndex]) ? value : [];
caches[othIndex] = (isCommon && value.length >= 120) ? createCache(othIndex && value) : null;
}
argsLength = args.length;
var array = args[0],
var array = arrays[0],
index = -1,
length = array ? array.length : 0,
result = [],
seen = caches[0];
outer:
while (++index < length) {
value = array[index];
if ((seen ? cacheIndexOf(seen, value) : indexOf(result, value, 0)) < 0) {
argsIndex = argsLength;
while (--argsIndex) {
var cache = caches[argsIndex];
if ((cache ? cacheIndexOf(cache, value) : indexOf(args[argsIndex], value, 0)) < 0) {
var othIndex = othLength;
while (--othIndex) {
var cache = caches[othIndex];
if ((cache ? cacheIndexOf(cache, value) : indexOf(arrays[othIndex], value, 0)) < 0) {
continue outer;
}
}
@@ -61,6 +53,6 @@ function intersection() {
}
}
return result;
}
});
module.exports = intersection;

View File

@@ -7,14 +7,11 @@ var arrayProto = Array.prototype;
var splice = arrayProto.splice;
/**
* Removes all provided values from `array` using `SameValueZero` for equality
* comparisons.
* Removes all provided values from `array` using
* [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* for equality comparisons.
*
* **Notes:**
* - Unlike `_.without`, this method mutates `array`
* - [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* comparisons are like strict equality comparisons, e.g. `===`, except
* that `NaN` matches `NaN`
* **Note:** Unlike `_.without`, this method mutates `array`.
*
* @static
* @memberOf _

View File

@@ -1,15 +1,9 @@
var baseAt = require('../internal/baseAt'),
baseCompareAscending = require('../internal/baseCompareAscending'),
baseFlatten = require('../internal/baseFlatten'),
isIndex = require('../internal/isIndex'),
basePullAt = require('../internal/basePullAt'),
restParam = require('../function/restParam');
/** Used for native method references. */
var arrayProto = Array.prototype;
/** Native method references. */
var splice = arrayProto.splice;
/**
* Removes elements from `array` corresponding to the given indexes and returns
* an array of the removed elements. Indexes may be specified as an array of
@@ -36,20 +30,10 @@ var splice = arrayProto.splice;
* // => [10, 20]
*/
var pullAt = restParam(function(array, indexes) {
array || (array = []);
indexes = baseFlatten(indexes);
var length = indexes.length,
result = baseAt(array, indexes);
indexes.sort(baseCompareAscending);
while (length--) {
var index = parseFloat(indexes[length]);
if (index != previous && isIndex(index)) {
var previous = index;
splice.call(array, index, 1);
}
}
var result = baseAt(array, indexes);
basePullAt(array, indexes.sort(baseCompareAscending));
return result;
});

View File

@@ -1,10 +1,5 @@
var baseCallback = require('../internal/baseCallback');
/** Used for native method references. */
var arrayProto = Array.prototype;
/** Native method references. */
var splice = arrayProto.splice;
var baseCallback = require('../internal/baseCallback'),
basePullAt = require('../internal/basePullAt');
/**
* Removes all elements from `array` that `predicate` returns truthy for
@@ -46,19 +41,23 @@ var splice = arrayProto.splice;
* // => [2, 4]
*/
function remove(array, predicate, thisArg) {
var result = [];
if (!(array && array.length)) {
return result;
}
var index = -1,
length = array ? array.length : 0,
result = [];
indexes = [],
length = array.length;
predicate = baseCallback(predicate, thisArg, 3);
while (++index < length) {
var value = array[index];
if (predicate(value, index, array)) {
result.push(value);
splice.call(array, index--, 1);
length--;
indexes.push(index);
}
}
basePullAt(array, indexes);
return result;
}

View File

@@ -4,7 +4,7 @@ var baseSlice = require('../internal/baseSlice'),
/**
* Creates a slice of `array` from `start` up to, but not including, `end`.
*
* **Note:** This function is used instead of `Array#slice` to support node
* **Note:** This method is used instead of `Array#slice` to support node
* lists in IE < 9 and to ensure dense arrays are returned.
*
* @static

View File

@@ -3,12 +3,9 @@ var baseFlatten = require('../internal/baseFlatten'),
restParam = require('../function/restParam');
/**
* Creates an array of unique values, in order, of the provided arrays using
* `SameValueZero` for equality comparisons.
*
* **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* comparisons are like strict equality comparisons, e.g. `===`, except that
* `NaN` matches `NaN`.
* Creates an array of unique values, in order, from all of the provided arrays
* using [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* for equality comparisons.
*
* @static
* @memberOf _

View File

@@ -4,12 +4,14 @@ var baseCallback = require('../internal/baseCallback'),
sortedUniq = require('../internal/sortedUniq');
/**
* Creates a duplicate-value-free version of an array using `SameValueZero`
* for equality comparisons. Providing `true` for `isSorted` performs a faster
* search algorithm for sorted arrays. If an iteratee function is provided it
* is invoked for each value in the array to generate the criterion by which
* uniqueness is computed. The `iteratee` is bound to `thisArg` and invoked
* with three arguments: (value, index, array).
* Creates a duplicate-free version of an array, using
* [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* for equality comparisons, in which only the first occurence of each element
* is kept. Providing `true` for `isSorted` performs a faster search algorithm
* for sorted arrays. If an iteratee function is provided it is invoked for
* each element in the array to generate the criterion by which uniqueness
* is computed. The `iteratee` is bound to `thisArg` and invoked with three
* arguments: (value, index, array).
*
* If a property name is provided for `iteratee` the created `_.property`
* style callback returns the property value of the given element.
@@ -22,10 +24,6 @@ var baseCallback = require('../internal/baseCallback'),
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* comparisons are like strict equality comparisons, e.g. `===`, except that
* `NaN` matches `NaN`.
*
* @static
* @memberOf _
* @alias unique
@@ -37,8 +35,8 @@ var baseCallback = require('../internal/baseCallback'),
* @returns {Array} Returns the new duplicate-value-free array.
* @example
*
* _.uniq([1, 2, 1]);
* // => [1, 2]
* _.uniq([2, 1, 2]);
* // => [2, 1]
*
* // using `isSorted`
* _.uniq([1, 1, 2], true);

View File

@@ -1,13 +1,14 @@
var arrayMap = require('../internal/arrayMap'),
arrayMax = require('../internal/arrayMax'),
baseProperty = require('../internal/baseProperty');
var arrayFilter = require('../internal/arrayFilter'),
arrayMap = require('../internal/arrayMap'),
baseProperty = require('../internal/baseProperty'),
isArrayLike = require('../internal/isArrayLike');
/** Used to the length of n-tuples for `_.unzip`. */
var getLength = baseProperty('length');
/* Native method references for those with the same name as other `lodash` methods. */
var nativeMax = Math.max;
/**
* This method is like `_.zip` except that it accepts an array of grouped
* elements and creates an array regrouping the elements to their pre-`_.zip`
* elements and creates an array regrouping the elements to their pre-zip
* configuration.
*
* @static
@@ -24,10 +25,19 @@ var getLength = baseProperty('length');
* // => [['fred', 'barney'], [30, 40], [true, false]]
*/
function unzip(array) {
if (!(array && array.length)) {
return [];
}
var index = -1,
length = (array && array.length && arrayMax(arrayMap(array, getLength))) >>> 0,
result = Array(length);
length = 0;
array = arrayFilter(array, function(group) {
if (isArrayLike(group)) {
length = nativeMax(group.length, length);
return true;
}
});
var result = Array(length);
while (++index < length) {
result[index] = arrayMap(array, baseProperty(index));
}

41
array/unzipWith.js Normal file
View File

@@ -0,0 +1,41 @@
var arrayMap = require('../internal/arrayMap'),
arrayReduce = require('../internal/arrayReduce'),
bindCallback = require('../internal/bindCallback'),
unzip = require('./unzip');
/**
* This method is like `_.unzip` except that it accepts an iteratee to specify
* how regrouped values should be combined. The `iteratee` is bound to `thisArg`
* and invoked with four arguments: (accumulator, value, index, group).
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array of grouped elements to process.
* @param {Function} [iteratee] The function to combine regrouped values.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Array} Returns the new array of regrouped elements.
* @example
*
* var zipped = _.zip([1, 2], [10, 20], [100, 200]);
* // => [[1, 10, 100], [2, 20, 200]]
*
* _.unzipWith(zipped, _.add);
* // => [3, 30, 300]
*/
function unzipWith(array, iteratee, thisArg) {
var length = array ? array.length : 0;
if (!length) {
return [];
}
var result = unzip(array);
if (iteratee == null) {
return result;
}
iteratee = bindCallback(iteratee, thisArg, 4);
return arrayMap(result, function(group) {
return arrayReduce(group, iteratee, undefined, true);
});
}
module.exports = unzipWith;

View File

@@ -1,15 +1,11 @@
var baseDifference = require('../internal/baseDifference'),
isArguments = require('../lang/isArguments'),
isArray = require('../lang/isArray'),
isArrayLike = require('../internal/isArrayLike'),
restParam = require('../function/restParam');
/**
* Creates an array excluding all provided values using `SameValueZero` for
* equality comparisons.
*
* **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* comparisons are like strict equality comparisons, e.g. `===`, except that
* `NaN` matches `NaN`.
* Creates an array excluding all provided values using
* [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* for equality comparisons.
*
* @static
* @memberOf _
@@ -23,7 +19,7 @@ var baseDifference = require('../internal/baseDifference'),
* // => [3]
*/
var without = restParam(function(array, values) {
return (isArray(array) || isArguments(array))
return isArrayLike(array)
? baseDifference(array, values)
: [];
});

View File

@@ -1,10 +1,9 @@
var baseDifference = require('../internal/baseDifference'),
baseUniq = require('../internal/baseUniq'),
isArguments = require('../lang/isArguments'),
isArray = require('../lang/isArray');
isArrayLike = require('../internal/isArrayLike');
/**
* Creates an array that is the [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
* Creates an array of unique values that is the [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
* of the provided arrays.
*
* @static
@@ -23,7 +22,7 @@ function xor() {
while (++index < length) {
var array = arguments[index];
if (isArray(array) || isArguments(array)) {
if (isArrayLike(array)) {
var result = result
? baseDifference(result, array).concat(baseDifference(array, result))
: array;

36
array/zipWith.js Normal file
View File

@@ -0,0 +1,36 @@
var restParam = require('../function/restParam'),
unzipWith = require('./unzipWith');
/**
* This method is like `_.zip` except that it accepts an iteratee to specify
* how grouped values should be combined. The `iteratee` is bound to `thisArg`
* and invoked with four arguments: (accumulator, value, index, group).
*
* @static
* @memberOf _
* @category Array
* @param {...Array} [arrays] The arrays to process.
* @param {Function} [iteratee] The function to combine grouped values.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Array} Returns the new array of grouped elements.
* @example
*
* _.zipWith([1, 2], [10, 20], [100, 200], _.add);
* // => [111, 222]
*/
var zipWith = restParam(function(arrays) {
var length = arrays.length,
iteratee = length > 2 ? arrays[length - 2] : undefined,
thisArg = length > 1 ? arrays[length - 1] : undefined;
if (length > 2 && typeof iteratee == 'function') {
length -= 2;
} else {
iteratee = (length > 1 && typeof thisArg == 'function') ? (--length, thisArg) : undefined;
thisArg = undefined;
}
arrays.length = length;
return unzipWith(arrays, iteratee, thisArg);
});
module.exports = zipWith;

View File

@@ -50,30 +50,31 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* `filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`, `forEach`,
* `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `functions`,
* `groupBy`, `indexBy`, `initial`, `intersection`, `invert`, `invoke`, `keys`,
* `keysIn`, `map`, `mapValues`, `matches`, `matchesProperty`, `memoize`, `merge`,
* `mixin`, `negate`, `noop`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
* `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`,
* `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `reverse`,
* `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`, `sortByOrder`, `splice`,
* `spread`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`,
* `throttle`, `thru`, `times`, `toArray`, `toPlainObject`, `transform`,
* `union`, `uniq`, `unshift`, `unzip`, `values`, `valuesIn`, `where`,
* `without`, `wrap`, `xor`, `zip`, and `zipObject`
* `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
* `memoize`, `merge`, `method`, `methodOf`, `mixin`, `negate`, `omit`, `once`,
* `pairs`, `partial`, `partialRight`, `partition`, `pick`, `plant`, `pluck`,
* `property`, `propertyOf`, `pull`, `pullAt`, `push`, `range`, `rearg`,
* `reject`, `remove`, `rest`, `restParam`, `reverse`, `set`, `shuffle`,
* `slice`, `sort`, `sortBy`, `sortByAll`, `sortByOrder`, `splice`, `spread`,
* `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, `throttle`,
* `thru`, `times`, `toArray`, `toPlainObject`, `transform`, `union`, `uniq`,
* `unshift`, `unzip`, `unzipWith`, `values`, `valuesIn`, `where`, `without`,
* `wrap`, `xor`, `zip`, `zipObject`, `zipWith`
*
* The wrapper methods that are **not** chainable by default are:
* `add`, `attempt`, `camelCase`, `capitalize`, `clone`, `cloneDeep`, `deburr`,
* `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`,
* `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`,
* `identity`, `includes`, `indexOf`, `inRange`, `isArguments`, `isArray`,
* `isBoolean`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`,
* `isFinite`,`isFunction`, `isMatch`, `isNative`, `isNaN`, `isNull`, `isNumber`,
* `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `get`,
* `gt`, `gte`, `has`, `identity`, `includes`, `indexOf`, `inRange`, `isArguments`,
* `isArray`, `isBoolean`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`,
* `isFinite` `isFunction`, `isMatch`, `isNative`, `isNaN`, `isNull`, `isNumber`,
* `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`,
* `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `max`, `min`,
* `noConflict`, `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`,
* `random`, `reduce`, `reduceRight`, `repeat`, `result`, `runInContext`,
* `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`,
* `startCase`, `startsWith`, `sum`, `template`, `trim`, `trimLeft`,
* `trimRight`, `trunc`, `unescape`, `uniqueId`, `value`, and `words`
* `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `lt`, `lte`,
* `max`, `min`, `noConflict`, `noop`, `now`, `pad`, `padLeft`, `padRight`,
* `parseInt`, `pop`, `random`, `reduce`, `reduceRight`, `repeat`, `result`,
* `runInContext`, `shift`, `size`, `snakeCase`, `some`, `sortedIndex`,
* `sortedLastIndex`, `startCase`, `startsWith`, `sum`, `template`, `trim`,
* `trimLeft`, `trimRight`, `trunc`, `unescape`, `uniqueId`, `value`, and `words`
*
* The wrapper method `sample` will return a wrapped value when `n` is provided,
* otherwise an unwrapped value is returned.
@@ -88,8 +89,8 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* var wrapped = _([1, 2, 3]);
*
* // returns an unwrapped value
* wrapped.reduce(function(sum, n) {
* return sum + n;
* wrapped.reduce(function(total, n) {
* return total + n;
* });
* // => 6
*

View File

@@ -1,8 +1,6 @@
var baseAt = require('../internal/baseAt'),
baseFlatten = require('../internal/baseFlatten'),
isLength = require('../internal/isLength'),
restParam = require('../function/restParam'),
toIterable = require('../internal/toIterable');
restParam = require('../function/restParam');
/**
* Creates an array of elements corresponding to the given keys, or indexes,
@@ -25,10 +23,6 @@ var baseAt = require('../internal/baseAt'),
* // => ['barney', 'pebbles']
*/
var at = restParam(function(collection, props) {
var length = collection ? collection.length : 0;
if (isLength(length)) {
collection = toIterable(collection);
}
return baseAt(collection, baseFlatten(props));
});

View File

@@ -57,7 +57,7 @@ function every(collection, predicate, thisArg) {
if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
predicate = null;
}
if (typeof predicate != 'function' || typeof thisArg != 'undefined') {
if (typeof predicate != 'function' || thisArg !== undefined) {
predicate = baseCallback(predicate, thisArg, 3);
}
return func(collection, predicate);

View File

@@ -5,10 +5,10 @@ var arrayEach = require('../internal/arrayEach'),
/**
* Iterates over elements of `collection` invoking `iteratee` for each element.
* The `iteratee` is bound to `thisArg` and invoked with three arguments:
* (value, index|key, collection). Iterator functions may exit iteration early
* (value, index|key, collection). Iteratee functions may exit iteration early
* by explicitly returning `false`.
*
* **Note:** As with other "Collections" methods, objects with a `length` property
* **Note:** As with other "Collections" methods, objects with a "length" property
* are iterated like arrays. To avoid this behavior `_.forIn` or `_.forOwn`
* may be used for object iteration.
*

View File

@@ -1,4 +1,5 @@
var baseIndexOf = require('../internal/baseIndexOf'),
getLength = require('../internal/getLength'),
isArray = require('../lang/isArray'),
isIterateeCall = require('../internal/isIterateeCall'),
isLength = require('../internal/isLength'),
@@ -9,13 +10,10 @@ var baseIndexOf = require('../internal/baseIndexOf'),
var nativeMax = Math.max;
/**
* Checks if `value` is in `collection` using `SameValueZero` for equality
* comparisons. If `fromIndex` is negative, it is used as the offset from
* the end of `collection`.
*
* **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* comparisons are like strict equality comparisons, e.g. `===`, except that
* `NaN` matches `NaN`.
* Checks if `value` is in `collection` using
* [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* for equality comparisons. If `fromIndex` is negative, it is used as the offset
* from the end of `collection`.
*
* @static
* @memberOf _
@@ -41,7 +39,7 @@ var nativeMax = Math.max;
* // => true
*/
function includes(collection, target, fromIndex, guard) {
var length = collection ? collection.length : 0;
var length = collection ? getLength(collection) : 0;
if (!isLength(length)) {
collection = values(collection);
length = collection.length;

View File

@@ -1,18 +1,20 @@
var baseEach = require('../internal/baseEach'),
isLength = require('../internal/isLength'),
invokePath = require('../internal/invokePath'),
isArrayLike = require('../internal/isArrayLike'),
isKey = require('../internal/isKey'),
restParam = require('../function/restParam');
/**
* Invokes the method named by `methodName` on each element in `collection`,
* returning an array of the results of each invoked method. Any additional
* arguments are provided to each invoked method. If `methodName` is a function
* it is invoked for, and `this` bound to, each element in `collection`.
* Invokes the method at `path` of each element in `collection`, returning
* an array of the results of each invoked method. Any additional arguments
* are provided to each invoked method. If `methodName` is a function it is
* invoked for, and `this` bound to, each element in `collection`.
*
* @static
* @memberOf _
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|string} methodName The name of the method to invoke or
* @param {Array|Function|string} path The path of the method to invoke or
* the function invoked per iteration.
* @param {...*} [args] The arguments to invoke the method with.
* @returns {Array} Returns the array of results.
@@ -24,15 +26,15 @@ var baseEach = require('../internal/baseEach'),
* _.invoke([123, 456], String.prototype.split, '');
* // => [['1', '2', '3'], ['4', '5', '6']]
*/
var invoke = restParam(function(collection, methodName, args) {
var invoke = restParam(function(collection, path, args) {
var index = -1,
isFunc = typeof methodName == 'function',
length = collection ? collection.length : 0,
result = isLength(length) ? Array(length) : [];
isFunc = typeof path == 'function',
isProp = isKey(path),
result = isArrayLike(collection) ? Array(collection.length) : [];
baseEach(collection, function(value) {
var func = isFunc ? methodName : (value != null && value[methodName]);
result[++index] = func ? func.apply(value, args) : undefined;
var func = isFunc ? path : ((isProp && value != null) ? value[path] : null);
result[++index] = func ? func.apply(value, args) : invokePath(value, path, args);
});
return result;
});

View File

@@ -19,14 +19,15 @@ var arrayMap = require('../internal/arrayMap'),
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* Many lodash methods are guarded to work as interatees for methods like
* Many lodash methods are guarded to work as iteratees for methods like
* `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
*
* The guarded methods are:
* `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`, `drop`,
* `dropRight`, `every`, `fill`, `flatten`, `invert`, `max`, `min`, `parseInt`,
* `slice`, `sortBy`, `take`, `takeRight`, `template`, `trim`, `trimLeft`,
* `trimRight`, `trunc`, `random`, `range`, `sample`, `some`, `uniq`, and `words`
* `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`,
* `drop`, `dropRight`, `every`, `fill`, `flatten`, `invert`, `max`, `min`,
* `parseInt`, `slice`, `sortBy`, `take`, `takeRight`, `template`, `trim`,
* `trimLeft`, `trimRight`, `trunc`, `random`, `range`, `sample`, `some`,
* `sum`, `uniq`, and `words`
*
* @static
* @memberOf _
@@ -35,7 +36,6 @@ var arrayMap = require('../internal/arrayMap'),
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [iteratee=_.identity] The function invoked
* per iteration.
* create a `_.property` or `_.matches` style callback respectively.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Array} Returns the new mapped array.
* @example

View File

@@ -1,14 +1,14 @@
var baseProperty = require('../internal/baseProperty'),
map = require('./map');
var map = require('./map'),
property = require('../utility/property');
/**
* Gets the value of `key` from all elements in `collection`.
* Gets the property value of `path` from all elements in `collection`.
*
* @static
* @memberOf _
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @param {string} key The key of the property to pluck.
* @param {Array|string} path The path of the property to pluck.
* @returns {Array} Returns the property values.
* @example
*
@@ -24,8 +24,8 @@ var baseProperty = require('../internal/baseProperty'),
* _.pluck(userIndex, 'age');
* // => [36, 40] (iteration order is not guaranteed)
*/
function pluck(collection, key) {
return map(collection, baseProperty(key));
function pluck(collection, path) {
return map(collection, property(path));
}
module.exports = pluck;

View File

@@ -10,7 +10,7 @@ var arrayReduce = require('../internal/arrayReduce'),
* value. The `iteratee` is bound to `thisArg` and invoked with four arguments:
* (accumulator, value, index|key, collection).
*
* Many lodash methods are guarded to work as interatees for methods like
* Many lodash methods are guarded to work as iteratees for methods like
* `_.reduce`, `_.reduceRight`, and `_.transform`.
*
* The guarded methods are:
@@ -27,8 +27,8 @@ var arrayReduce = require('../internal/arrayReduce'),
* @returns {*} Returns the accumulated value.
* @example
*
* _.reduce([1, 2], function(sum, n) {
* return sum + n;
* _.reduce([1, 2], function(total, n) {
* return total + n;
* });
* // => 3
*

View File

@@ -24,6 +24,6 @@ var arrayReduceRight = require('../internal/arrayReduceRight'),
* }, []);
* // => [4, 5, 2, 3, 0, 1]
*/
var reduceRight = createReduce(arrayReduceRight, baseEachRight);
var reduceRight = createReduce(arrayReduceRight, baseEachRight);
module.exports = reduceRight;

View File

@@ -7,17 +7,6 @@ var arrayFilter = require('../internal/arrayFilter'),
* The opposite of `_.filter`; this method returns the elements of `collection`
* that `predicate` does **not** return truthy for.
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
* @category Collection

View File

@@ -1,6 +1,6 @@
var baseRandom = require('../internal/baseRandom'),
isIterateeCall = require('../internal/isIterateeCall'),
shuffle = require('./shuffle'),
toArray = require('../lang/toArray'),
toIterable = require('../internal/toIterable');
/* Native method references for those with the same name as other `lodash` methods. */
@@ -30,8 +30,20 @@ function sample(collection, n, guard) {
var length = collection.length;
return length > 0 ? collection[baseRandom(0, length - 1)] : undefined;
}
var result = shuffle(collection);
result.length = nativeMin(n < 0 ? 0 : (+n || 0), result.length);
var index = -1,
result = toArray(collection),
length = result.length,
lastIndex = length - 1;
n = nativeMin(n < 0 ? 0 : (+n || 0), length);
while (++index < n) {
var rand = baseRandom(index, lastIndex),
value = result[rand];
result[rand] = result[index];
result[index] = value;
}
result.length = n;
return result;
}

View File

@@ -1,5 +1,7 @@
var baseRandom = require('../internal/baseRandom'),
toIterable = require('../internal/toIterable');
var sample = require('./sample');
/** Used as references for `-Infinity` and `Infinity`. */
var POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
/**
* Creates an array of shuffled values, using a version of the
@@ -16,20 +18,7 @@ var baseRandom = require('../internal/baseRandom'),
* // => [4, 1, 3, 2]
*/
function shuffle(collection) {
collection = toIterable(collection);
var index = -1,
length = collection.length,
result = Array(length);
while (++index < length) {
var rand = baseRandom(0, index);
if (index != rand) {
result[index] = result[rand];
}
result[rand] = collection[index];
}
return result;
return sample(collection, POSITIVE_INFINITY);
}
module.exports = shuffle;

View File

@@ -1,4 +1,5 @@
var isLength = require('../internal/isLength'),
var getLength = require('../internal/getLength'),
isLength = require('../internal/isLength'),
keys = require('../object/keys');
/**
@@ -22,7 +23,7 @@ var isLength = require('../internal/isLength'),
* // => 7
*/
function size(collection) {
var length = collection ? collection.length : 0;
var length = collection ? getLength(collection) : 0;
return isLength(length) ? length : keys(collection).length;
}

View File

@@ -58,7 +58,7 @@ function some(collection, predicate, thisArg) {
if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
predicate = null;
}
if (typeof predicate != 'function' || typeof thisArg != 'undefined') {
if (typeof predicate != 'function' || thisArg !== undefined) {
predicate = baseCallback(predicate, thisArg, 3);
}
return func(collection, predicate);

View File

@@ -1,9 +1,8 @@
var baseCallback = require('../internal/baseCallback'),
baseEach = require('../internal/baseEach'),
baseMap = require('../internal/baseMap'),
baseSortBy = require('../internal/baseSortBy'),
compareAscending = require('../internal/compareAscending'),
isIterateeCall = require('../internal/isIterateeCall'),
isLength = require('../internal/isLength');
isIterateeCall = require('../internal/isIterateeCall');
/**
* Creates an array of elements, sorted in ascending order by the results of
@@ -27,9 +26,8 @@ var baseCallback = require('../internal/baseCallback'),
* @memberOf _
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Array|Function|Object|string} [iteratee=_.identity] The function
* invoked per iteration. If a property name or an object is provided it is
* used to create a `_.property` or `_.matches` style callback respectively.
* @param {Function|Object|string} [iteratee=_.identity] The function invoked
* per iteration.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Array} Returns the new sorted array.
* @example
@@ -58,16 +56,14 @@ function sortBy(collection, iteratee, thisArg) {
if (collection == null) {
return [];
}
var index = -1,
length = collection.length,
result = isLength(length) ? Array(length) : [];
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
iteratee = null;
}
var index = -1;
iteratee = baseCallback(iteratee, thisArg, 3);
baseEach(collection, function(value, key, collection) {
result[++index] = { 'criteria': iteratee(value, key, collection), 'index': index, 'value': value };
var result = baseMap(collection, function(value, key, collection) {
return { 'criteria': iteratee(value, key, collection), 'index': ++index, 'value': value };
});
return baseSortBy(result, compareAscending);
}

View File

@@ -1,48 +1,52 @@
var baseFlatten = require('../internal/baseFlatten'),
baseSortByOrder = require('../internal/baseSortByOrder'),
isIterateeCall = require('../internal/isIterateeCall');
isIterateeCall = require('../internal/isIterateeCall'),
restParam = require('../function/restParam');
/**
* This method is like `_.sortBy` except that it sorts by property names
* instead of an iteratee function.
* This method is like `_.sortBy` except that it can sort by multiple iteratees
* or property names.
*
* If a property name is provided for an iteratee the created `_.property`
* style callback returns the property value of the given element.
*
* If an object is provided for an iteratee the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @param {...(string|string[])} props The property names to sort by,
* specified as individual property names or arrays of property names.
* @param {...(Function|Function[]|Object|Object[]|string|string[])} iteratees
* The iteratees to sort by, specified as individual values or arrays of values.
* @returns {Array} Returns the new sorted array.
* @example
*
* var users = [
* { 'user': 'fred', 'age': 48 },
* { 'user': 'barney', 'age': 36 },
* { 'user': 'fred', 'age': 40 },
* { 'user': 'barney', 'age': 26 },
* { 'user': 'fred', 'age': 30 }
* { 'user': 'fred', 'age': 42 },
* { 'user': 'barney', 'age': 34 }
* ];
*
* _.map(_.sortByAll(users, ['user', 'age']), _.values);
* // => [['barney', 26], ['barney', 36], ['fred', 30], ['fred', 40]]
* // => [['barney', 34], ['barney', 36], ['fred', 42], ['fred', 48]]
*
* _.map(_.sortByAll(users, 'user', function(chr) {
* return Math.floor(chr.age / 10);
* }), _.values);
* // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
*/
function sortByAll() {
var args = arguments,
collection = args[0],
guard = args[3],
index = 0,
length = args.length - 1;
var sortByAll = restParam(function(collection, iteratees) {
if (collection == null) {
return [];
}
var props = Array(length);
while (index < length) {
props[index] = args[++index];
var guard = iteratees[2];
if (guard && isIterateeCall(iteratees[0], iteratees[1], guard)) {
iteratees.length = 1;
}
if (guard && isIterateeCall(args[1], args[2], guard)) {
props = args[1];
}
return baseSortByOrder(collection, baseFlatten(props), []);
}
return baseSortByOrder(collection, baseFlatten(iteratees), []);
});
module.exports = sortByAll;

View File

@@ -4,45 +4,52 @@ var baseSortByOrder = require('../internal/baseSortByOrder'),
/**
* This method is like `_.sortByAll` except that it allows specifying the
* sort orders of the property names to sort by. A truthy value in `orders`
* will sort the corresponding property name in ascending order while a
* falsey value will sort it in descending order.
* sort orders of the iteratees to sort by. A truthy value in `orders` will
* sort the corresponding property name in ascending order while a falsey
* value will sort it in descending order.
*
* If a property name is provided for an iteratee the created `_.property`
* style callback returns the property value of the given element.
*
* If an object is provided for an iteratee the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @param {string[]} props The property names to sort by.
* @param {boolean[]} orders The sort orders of `props`.
* @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
* @param {boolean[]} orders The sort orders of `iteratees`.
* @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.
* @returns {Array} Returns the new sorted array.
* @example
*
* var users = [
* { 'user': 'barney', 'age': 26 },
* { 'user': 'fred', 'age': 40 },
* { 'user': 'barney', 'age': 36 },
* { 'user': 'fred', 'age': 30 }
* { 'user': 'fred', 'age': 48 },
* { 'user': 'barney', 'age': 34 },
* { 'user': 'fred', 'age': 42 },
* { 'user': 'barney', 'age': 36 }
* ];
*
* // sort by `user` in ascending order and by `age` in descending order
* _.map(_.sortByOrder(users, ['user', 'age'], [true, false]), _.values);
* // => [['barney', 36], ['barney', 26], ['fred', 40], ['fred', 30]]
* // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
*/
function sortByOrder(collection, props, orders, guard) {
function sortByOrder(collection, iteratees, orders, guard) {
if (collection == null) {
return [];
}
if (guard && isIterateeCall(props, orders, guard)) {
if (guard && isIterateeCall(iteratees, orders, guard)) {
orders = null;
}
if (!isArray(props)) {
props = props == null ? [] : [props];
if (!isArray(iteratees)) {
iteratees = iteratees == null ? [] : [iteratees];
}
if (!isArray(orders)) {
orders = orders == null ? [] : [orders];
}
return baseSortByOrder(collection, props, orders);
return baseSortByOrder(collection, iteratees, orders);
}
module.exports = sortByOrder;

View File

@@ -1,7 +1,7 @@
var isNative = require('../lang/isNative');
var getNative = require('../internal/getNative');
/* Native method references for those with the same name as other `lodash` methods. */
var nativeNow = isNative(nativeNow = Date.now) && nativeNow;
var nativeNow = getNative(Date, 'now');
/**
* Gets the number of milliseconds that have elapsed since the Unix epoch

View File

@@ -31,7 +31,8 @@ function before(n, func) {
return function() {
if (--n > 0) {
result = func.apply(this, arguments);
} else {
}
if (n <= 1) {
func = null;
}
return result;

View File

@@ -14,7 +14,7 @@ var BIND_FLAG = 1,
* The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
* may be used as a placeholder for partially applied arguments.
*
* **Note:** Unlike native `Function#bind` this method does not set the `length`
* **Note:** Unlike native `Function#bind` this method does not set the "length"
* property of bound functions.
*
* @static

View File

@@ -12,7 +12,7 @@ var BIND_FLAG = 1;
* of method names. If no method names are provided all enumerable function
* properties, own and inherited, of `object` are bound.
*
* **Note:** This method does not set the `length` property of bound functions.
* **Note:** This method does not set the "length" property of bound functions.
*
* @static
* @memberOf _

View File

@@ -13,7 +13,7 @@ var BIND_FLAG = 1,
*
* This method differs from `_.bind` by allowing bound functions to reference
* methods that may be redefined or don't yet exist.
* See [Peter Michaux's article](http://michaux.ca/articles/lazy-function-definition-pattern)
* See [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
* for more details.
*
* The `_.bindKey.placeholder` value, which defaults to `_` in monolithic

View File

@@ -13,7 +13,7 @@ var CURRY_FLAG = 8;
* The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
* may be used as a placeholder for provided arguments.
*
* **Note:** This method does not set the `length` property of curried functions.
* **Note:** This method does not set the "length" property of curried functions.
*
* @static
* @memberOf _

View File

@@ -10,7 +10,7 @@ var CURRY_RIGHT_FLAG = 16;
* The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
* builds, may be used as a placeholder for provided arguments.
*
* **Note:** This method does not set the `length` property of curried functions.
* **Note:** This method does not set the "length" property of curried functions.
*
* @static
* @memberOf _

View File

@@ -8,12 +8,13 @@ var FUNC_ERROR_TEXT = 'Expected a function';
var nativeMax = Math.max;
/**
* Creates a function that delays invoking `func` until after `wait` milliseconds
* have elapsed since the last time it was invoked. The created function comes
* with a `cancel` method to cancel delayed invocations. Provide an options
* object to indicate that `func` should be invoked on the leading and/or
* trailing edge of the `wait` timeout. Subsequent calls to the debounced
* function return the result of the last `func` invocation.
* Creates a debounced function that delays invoking `func` until after `wait`
* milliseconds have elapsed since the last time the debounced function was
* invoked. The debounced function comes with a `cancel` method to cancel
* delayed invocations. Provide an options object to indicate that `func`
* should be invoked on the leading and/or trailing edge of the `wait` timeout.
* Subsequent calls to the debounced function return the result of the last
* `func` invocation.
*
* **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
* on the trailing edge of the timeout only if the the debounced function is

View File

@@ -60,14 +60,14 @@ function memoize(func, resolver) {
}
var memoized = function() {
var args = arguments,
cache = memoized.cache,
key = resolver ? resolver.apply(this, args) : args[0];
key = resolver ? resolver.apply(this, args) : args[0],
cache = memoized.cache;
if (cache.has(key)) {
return cache.get(key);
}
var result = func.apply(this, args);
cache.set(key, result);
memoized.cache = cache.set(key, result);
return result;
};
memoized.cache = new memoize.Cache;

View File

@@ -18,7 +18,7 @@ var before = require('./before');
* // `initialize` invokes `createApplication` once
*/
function once(func) {
return before(func, 2);
return before(2, func);
}
module.exports = once;

View File

@@ -11,7 +11,7 @@ var PARTIAL_FLAG = 32;
* The `_.partial.placeholder` value, which defaults to `_` in monolithic
* builds, may be used as a placeholder for partially applied arguments.
*
* **Note:** This method does not set the `length` property of partially
* **Note:** This method does not set the "length" property of partially
* applied functions.
*
* @static

View File

@@ -10,7 +10,7 @@ var PARTIAL_RIGHT_FLAG = 64;
* The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
* builds, may be used as a placeholder for partially applied arguments.
*
* **Note:** This method does not set the `length` property of partially
* **Note:** This method does not set the "length" property of partially
* applied functions.
*
* @static

View File

@@ -30,7 +30,7 @@ function restParam(func, start) {
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
}
start = nativeMax(typeof start == 'undefined' ? (func.length - 1) : (+start || 0), 0);
start = nativeMax(start === undefined ? (func.length - 1) : (+start || 0), 0);
return function() {
var args = arguments,
index = -1,

View File

@@ -12,12 +12,12 @@ var debounceOptions = {
};
/**
* Creates a function that only invokes `func` at most once per every `wait`
* milliseconds. The created function comes with a `cancel` method to cancel
* delayed invocations. Provide an options object to indicate that `func`
* should be invoked on the leading and/or trailing edge of the `wait` timeout.
* Subsequent calls to the throttled function return the result of the last
* `func` call.
* Creates a throttled function that only invokes `func` at most once per
* every `wait` milliseconds. The throttled function comes with a `cancel`
* method to cancel delayed invocations. Provide an options object to indicate
* that `func` should be invoked on the leading and/or trailing edge of the
* `wait` timeout. Subsequent calls to the throttled function return the
* result of the last `func` call.
*
* **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
* on the trailing edge of the timeout only if the the throttled function is

2322
index.js

File diff suppressed because it is too large Load Diff

View File

@@ -1,11 +1,11 @@
var cachePush = require('./cachePush'),
isNative = require('../lang/isNative');
getNative = require('./getNative');
/** Native method references. */
var Set = isNative(Set = global.Set) && Set;
var Set = getNative(global, 'Set');
/* Native method references for those with the same name as other `lodash` methods. */
var nativeCreate = isNative(nativeCreate = Object.create) && nativeCreate;
var nativeCreate = getNative(Object, 'create');
/**
*

30
internal/arrayExtremum.js Normal file
View File

@@ -0,0 +1,30 @@
/**
* A specialized version of `baseExtremum` for arrays which invokes `iteratee`
* with one argument: (value).
*
* @private
* @param {Array} array The array to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @param {Function} comparator The function used to compare values.
* @param {*} exValue The initial extremum value.
* @returns {*} Returns the extremum value.
*/
function arrayExtremum(array, iteratee, comparator, exValue) {
var index = -1,
length = array.length,
computed = exValue,
result = computed;
while (++index < length) {
var value = array[index],
current = +iteratee(value);
if (comparator(current, computed)) {
computed = current;
result = value;
}
}
return result;
}
module.exports = arrayExtremum;

View File

@@ -1,25 +0,0 @@
/** Used as references for `-Infinity` and `Infinity`. */
var NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY;
/**
* A specialized version of `_.max` for arrays without support for iteratees.
*
* @private
* @param {Array} array The array to iterate over.
* @returns {*} Returns the maximum value.
*/
function arrayMax(array) {
var index = -1,
length = array.length,
result = NEGATIVE_INFINITY;
while (++index < length) {
var value = array[index];
if (value > result) {
result = value;
}
}
return result;
}
module.exports = arrayMax;

View File

@@ -1,25 +0,0 @@
/** Used as references for `-Infinity` and `Infinity`. */
var POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
/**
* A specialized version of `_.min` for arrays without support for iteratees.
*
* @private
* @param {Array} array The array to iterate over.
* @returns {*} Returns the minimum value.
*/
function arrayMin(array) {
var index = -1,
length = array.length,
result = POSITIVE_INFINITY;
while (++index < length) {
var value = array[index];
if (value < result) {
result = value;
}
}
return result;
}
module.exports = arrayMin;

View File

@@ -7,7 +7,7 @@
* @returns {*} Returns the value to assign to the destination object.
*/
function assignDefaults(objectValue, sourceValue) {
return typeof objectValue == 'undefined' ? sourceValue : objectValue;
return objectValue === undefined ? sourceValue : objectValue;
}
module.exports = assignDefaults;

View File

@@ -7,7 +7,7 @@ var hasOwnProperty = objectProto.hasOwnProperty;
/**
* Used by `_.template` to customize its `_.assign` use.
*
* **Note:** This method is like `assignDefaults` except that it ignores
* **Note:** This function is like `assignDefaults` except that it ignores
* inherited property values when checking if a property is `undefined`.
*
* @private
@@ -18,7 +18,7 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* @returns {*} Returns the value to assign to the destination object.
*/
function assignOwnDefaults(objectValue, sourceValue, key, object) {
return (typeof objectValue == 'undefined' || !hasOwnProperty.call(object, key))
return (objectValue === undefined || !hasOwnProperty.call(object, key))
? sourceValue
: objectValue;
}

32
internal/assignWith.js Normal file
View File

@@ -0,0 +1,32 @@
var keys = require('../object/keys');
/**
* A specialized version of `_.assign` for customizing assigned values without
* support for argument juggling, multiple sources, and `this` binding `customizer`
* functions.
*
* @private
* @param {Object} object The destination object.
* @param {Object} source The source object.
* @param {Function} customizer The function to customize assigned values.
* @returns {Object} Returns `object`.
*/
function assignWith(object, source, customizer) {
var index = -1,
props = keys(source),
length = props.length;
while (++index < length) {
var key = props[index],
value = object[key],
result = customizer(value, source[key], key, object, source);
if ((result === result ? (result !== value) : (value === value)) ||
(value === undefined && !(key in object))) {
object[key] = result;
}
}
return object;
}
module.exports = assignWith;

View File

@@ -3,33 +3,17 @@ var baseCopy = require('./baseCopy'),
/**
* The base implementation of `_.assign` without support for argument juggling,
* multiple sources, and `this` binding `customizer` functions.
* multiple sources, and `customizer` functions.
*
* @private
* @param {Object} object The destination object.
* @param {Object} source The source object.
* @param {Function} [customizer] The function to customize assigning values.
* @returns {Object} Returns the destination object.
* @returns {Object} Returns `object`.
*/
function baseAssign(object, source, customizer) {
var props = keys(source);
if (!customizer) {
return baseCopy(source, object, props);
}
var index = -1,
length = props.length;
while (++index < length) {
var key = props[index],
value = object[key],
result = customizer(value, source[key], key, object, source);
if ((result === result ? (result !== value) : (value === value)) ||
(typeof value == 'undefined' && !(key in object))) {
object[key] = result;
}
}
return object;
function baseAssign(object, source) {
return source == null
? object
: baseCopy(source, keys(source), object);
}
module.exports = baseAssign;

View File

@@ -1,29 +1,29 @@
var isIndex = require('./isIndex'),
isLength = require('./isLength');
var isArrayLike = require('./isArrayLike'),
isIndex = require('./isIndex');
/**
* The base implementation of `_.at` without support for strings and individual
* key arguments.
* The base implementation of `_.at` without support for string collections
* and individual key arguments.
*
* @private
* @param {Array|Object} collection The collection to iterate over.
* @param {number[]|string[]} [props] The property names or indexes of elements to pick.
* @param {number[]|string[]} props The property names or indexes of elements to pick.
* @returns {Array} Returns the new array of picked elements.
*/
function baseAt(collection, props) {
var index = -1,
length = collection.length,
isArr = isLength(length),
isNil = collection == null,
isArr = !isNil && isArrayLike(collection),
length = isArr ? collection.length : 0,
propsLength = props.length,
result = Array(propsLength);
while(++index < propsLength) {
var key = props[index];
if (isArr) {
key = parseFloat(key);
result[index] = isIndex(key, length) ? collection[key] : undefined;
} else {
result[index] = collection[key];
result[index] = isNil ? undefined : collection[key];
}
}
return result;

View File

@@ -1,8 +1,8 @@
var baseMatches = require('./baseMatches'),
baseMatchesProperty = require('./baseMatchesProperty'),
baseProperty = require('./baseProperty'),
bindCallback = require('./bindCallback'),
identity = require('../utility/identity');
identity = require('../utility/identity'),
property = require('../utility/property');
/**
* The base implementation of `_.callback` which supports specifying the
@@ -17,7 +17,7 @@ var baseMatches = require('./baseMatches'),
function baseCallback(func, thisArg, argCount) {
var type = typeof func;
if (type == 'function') {
return typeof thisArg == 'undefined'
return thisArg === undefined
? func
: bindCallback(func, thisArg, argCount);
}
@@ -27,9 +27,9 @@ function baseCallback(func, thisArg, argCount) {
if (type == 'object') {
return baseMatches(func);
}
return typeof thisArg == 'undefined'
? baseProperty(func + '')
: baseMatchesProperty(func + '', thisArg);
return thisArg === undefined
? property(func)
: baseMatchesProperty(func, thisArg);
}
module.exports = baseCallback;

View File

@@ -1,13 +1,12 @@
var arrayCopy = require('./arrayCopy'),
arrayEach = require('./arrayEach'),
baseCopy = require('./baseCopy'),
baseAssign = require('./baseAssign'),
baseForOwn = require('./baseForOwn'),
initCloneArray = require('./initCloneArray'),
initCloneByTag = require('./initCloneByTag'),
initCloneObject = require('./initCloneObject'),
isArray = require('../lang/isArray'),
isObject = require('../lang/isObject'),
keys = require('../object/keys');
isObject = require('../lang/isObject');
/** `Object#toString` result references. */
var argsTag = '[object Arguments]',
@@ -78,7 +77,7 @@ function baseClone(value, isDeep, customizer, key, object, stackA, stackB) {
if (customizer) {
result = object ? customizer(value, key, object) : customizer(value);
}
if (typeof result != 'undefined') {
if (result !== undefined) {
return result;
}
if (!isObject(value)) {
@@ -97,7 +96,7 @@ function baseClone(value, isDeep, customizer, key, object, stackA, stackB) {
if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
result = initCloneObject(isFunc ? {} : value);
if (!isDeep) {
return baseCopy(value, result, keys(value));
return baseAssign(result, value);
}
} else {
return cloneableTags[tag]

View File

@@ -3,19 +3,28 @@
* sorts them in ascending order without guaranteeing a stable sort.
*
* @private
* @param {*} value The value to compare to `other`.
* @param {*} other The value to compare to `value`.
* @param {*} value The value to compare.
* @param {*} other The other value to compare.
* @returns {number} Returns the sort order indicator for `value`.
*/
function baseCompareAscending(value, other) {
if (value !== other) {
var valIsReflexive = value === value,
var valIsNull = value === null,
valIsUndef = value === undefined,
valIsReflexive = value === value;
var othIsNull = other === null,
othIsUndef = other === undefined,
othIsReflexive = other === other;
if (value > other || !valIsReflexive || (typeof value == 'undefined' && othIsReflexive)) {
if ((value > other && !othIsNull) || !valIsReflexive ||
(valIsNull && !othIsUndef && othIsReflexive) ||
(valIsUndef && othIsReflexive)) {
return 1;
}
if (value < other || !othIsReflexive || (typeof other == 'undefined' && valIsReflexive)) {
if ((value < other && !valIsNull) || !othIsReflexive ||
(othIsNull && !valIsUndef && valIsReflexive) ||
(othIsUndef && valIsReflexive)) {
return -1;
}
}

View File

@@ -1,17 +1,15 @@
/**
* Copies the properties of `source` to `object`.
* Copies properties of `source` to `object`.
*
* @private
* @param {Object} source The object to copy properties from.
* @param {Object} [object={}] The object to copy properties to.
* @param {Array} props The property names to copy.
* @param {Object} [object={}] The object to copy properties to.
* @returns {Object} Returns `object`.
*/
function baseCopy(source, object, props) {
if (!props) {
props = object;
object = {};
}
function baseCopy(source, props, object) {
object || (object = {});
var index = -1,
length = props.length;

View File

@@ -9,14 +9,14 @@ var isObject = require('../lang/isObject');
* @returns {Object} Returns the new object.
*/
var baseCreate = (function() {
function Object() {}
function object() {}
return function(prototype) {
if (isObject(prototype)) {
Object.prototype = prototype;
var result = new Object;
Object.prototype = null;
object.prototype = prototype;
var result = new object;
object.prototype = null;
}
return result || global.Object();
return result || {};
};
}());

View File

@@ -1,30 +1,24 @@
var baseEach = require('./baseEach');
/** Used as references for `-Infinity` and `Infinity`. */
var NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY,
POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
/**
* Gets the extremum value of `collection` invoking `iteratee` for each value
* in `collection` to generate the criterion by which the value is ranked.
* The `iteratee` is invoked with three arguments: (value, index, collection).
* The `iteratee` is invoked with three arguments: (value, index|key, collection).
*
* @private
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @param {boolean} [isMin] Specify returning the minimum, instead of the
* maximum, extremum value.
* @param {Function} comparator The function used to compare values.
* @param {*} exValue The initial extremum value.
* @returns {*} Returns the extremum value.
*/
function extremumBy(collection, iteratee, isMin) {
var exValue = isMin ? POSITIVE_INFINITY : NEGATIVE_INFINITY,
computed = exValue,
function baseExtremum(collection, iteratee, comparator, exValue) {
var computed = exValue,
result = computed;
baseEach(collection, function(value, index, collection) {
var current = iteratee(value, index, collection);
if ((isMin ? (current < computed) : (current > computed)) ||
(current === exValue && current === result)) {
var current = +iteratee(value, index, collection);
if (comparator(current, computed) || (current === exValue && current === result)) {
computed = current;
result = value;
}
@@ -32,4 +26,4 @@ function extremumBy(collection, iteratee, isMin) {
return result;
}
module.exports = extremumBy;
module.exports = baseExtremum;

View File

@@ -15,7 +15,7 @@ function baseFill(array, value, start, end) {
if (start < 0) {
start = -start > length ? 0 : (length + start);
}
end = (typeof end == 'undefined' || end > length) ? length : (+end || 0);
end = (end === undefined || end > length) ? length : (+end || 0);
if (end < 0) {
end += length;
}

View File

@@ -1,6 +1,6 @@
var isArguments = require('../lang/isArguments'),
isArray = require('../lang/isArray'),
isLength = require('./isLength'),
isArrayLike = require('./isArrayLike'),
isObjectLike = require('./isObjectLike');
/**
@@ -9,8 +9,8 @@ var isArguments = require('../lang/isArguments'),
*
* @private
* @param {Array} array The array to flatten.
* @param {boolean} isDeep Specify a deep flatten.
* @param {boolean} isStrict Restrict flattening to arrays and `arguments` objects.
* @param {boolean} [isDeep] Specify a deep flatten.
* @param {boolean} [isStrict] Restrict flattening to arrays-like objects.
* @returns {Array} Returns the new flattened array.
*/
function baseFlatten(array, isDeep, isStrict) {
@@ -21,8 +21,8 @@ function baseFlatten(array, isDeep, isStrict) {
while (++index < length) {
var value = array[index];
if (isObjectLike(value) && isLength(value.length) && (isArray(value) || isArguments(value))) {
if (isObjectLike(value) && isArrayLike(value) &&
(isStrict || isArray(value) || isArguments(value))) {
if (isDeep) {
// Recursively flatten arrays (susceptible to call stack limits).
value = baseFlatten(value, isDeep, isStrict);
@@ -30,7 +30,6 @@ function baseFlatten(array, isDeep, isStrict) {
var valIndex = -1,
valLength = value.length;
result.length += valLength;
while (++valIndex < valLength) {
result[++resIndex] = value[valIndex];
}

View File

@@ -3,7 +3,7 @@ var createBaseFor = require('./createBaseFor');
/**
* The base implementation of `baseForIn` and `baseForOwn` which iterates
* over `object` properties returned by `keysFunc` invoking `iteratee` for
* each property. Iterator functions may exit iteration early by explicitly
* each property. Iteratee functions may exit iteration early by explicitly
* returning `false`.
*
* @private

29
internal/baseGet.js Normal file
View File

@@ -0,0 +1,29 @@
var toObject = require('./toObject');
/**
* The base implementation of `get` without support for string paths
* and default values.
*
* @private
* @param {Object} object The object to query.
* @param {Array} path The path of the property to get.
* @param {string} [pathKey] The key representation of path.
* @returns {*} Returns the resolved value.
*/
function baseGet(object, path, pathKey) {
if (object == null) {
return;
}
if (pathKey !== undefined && pathKey in toObject(object)) {
path = [pathKey];
}
var index = 0,
length = path.length;
while (object != null && index < length) {
object = object[path[index++]];
}
return (index && index == length) ? object : undefined;
}
module.exports = baseGet;

View File

@@ -1,4 +1,6 @@
var baseIsEqualDeep = require('./baseIsEqualDeep');
var baseIsEqualDeep = require('./baseIsEqualDeep'),
isObject = require('../lang/isObject'),
isObjectLike = require('./isObjectLike');
/**
* The base implementation of `_.isEqual` without support for `this` binding
@@ -14,18 +16,10 @@ var baseIsEqualDeep = require('./baseIsEqualDeep');
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
*/
function baseIsEqual(value, other, customizer, isLoose, stackA, stackB) {
// Exit early for identical values.
if (value === other) {
// Treat `+0` vs. `-0` as not equal.
return value !== 0 || (1 / value == 1 / other);
return true;
}
var valType = typeof value,
othType = typeof other;
// Exit early for unlike primitive values.
if ((valType != 'function' && valType != 'object' && othType != 'function' && othType != 'object') ||
value == null || other == null) {
// Return `false` unless both values are `NaN`.
if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
return value !== value && other !== other;
}
return baseIsEqualDeep(value, other, baseIsEqual, customizer, isLoose, stackA, stackB);

View File

@@ -7,7 +7,6 @@ var equalArrays = require('./equalArrays'),
/** `Object#toString` result references. */
var argsTag = '[object Arguments]',
arrayTag = '[object Array]',
funcTag = '[object Function]',
objectTag = '[object Object]';
/** Used for native method references. */
@@ -59,28 +58,24 @@ function baseIsEqualDeep(object, other, equalFunc, customizer, isLoose, stackA,
othIsArr = isTypedArray(other);
}
}
var objIsObj = (objTag == objectTag || (isLoose && objTag == funcTag)),
othIsObj = (othTag == objectTag || (isLoose && othTag == funcTag)),
var objIsObj = objTag == objectTag,
othIsObj = othTag == objectTag,
isSameTag = objTag == othTag;
if (isSameTag && !(objIsArr || objIsObj)) {
return equalByTag(object, other, objTag);
}
if (isLoose) {
if (!isSameTag && !(objIsObj && othIsObj)) {
return false;
}
} else {
var valWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
othWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
if (!isLoose) {
var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
if (valWrapped || othWrapped) {
return equalFunc(valWrapped ? object.value() : object, othWrapped ? other.value() : other, customizer, isLoose, stackA, stackB);
}
if (!isSameTag) {
return false;
if (objIsWrapped || othIsWrapped) {
return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? other.value() : other, customizer, isLoose, stackA, stackB);
}
}
if (!isSameTag) {
return false;
}
// Assume cyclic values are equal.
// For more information on detecting circular references see https://es5.github.io/#JO.
stackA || (stackA = []);

View File

@@ -1,4 +1,5 @@
var baseIsEqual = require('./baseIsEqual');
var baseIsEqual = require('./baseIsEqual'),
toObject = require('./toObject');
/**
* The base implementation of `_.isMatch` without support for callback
@@ -6,41 +7,43 @@ var baseIsEqual = require('./baseIsEqual');
*
* @private
* @param {Object} object The object to inspect.
* @param {Array} props The source property names to match.
* @param {Array} values The source values to match.
* @param {Array} strictCompareFlags Strict comparison flags for source values.
* @param {Array} matchData The propery names, values, and compare flags to match.
* @param {Function} [customizer] The function to customize comparing objects.
* @returns {boolean} Returns `true` if `object` is a match, else `false`.
*/
function baseIsMatch(object, props, values, strictCompareFlags, customizer) {
var index = -1,
length = props.length,
function baseIsMatch(object, matchData, customizer) {
var index = matchData.length,
length = index,
noCustomizer = !customizer;
while (++index < length) {
if ((noCustomizer && strictCompareFlags[index])
? values[index] !== object[props[index]]
: !(props[index] in object)
if (object == null) {
return !length;
}
object = toObject(object);
while (index--) {
var data = matchData[index];
if ((noCustomizer && data[2])
? data[1] !== object[data[0]]
: !(data[0] in object)
) {
return false;
}
}
index = -1;
while (++index < length) {
var key = props[index],
data = matchData[index];
var key = data[0],
objValue = object[key],
srcValue = values[index];
srcValue = data[1];
if (noCustomizer && strictCompareFlags[index]) {
var result = typeof objValue != 'undefined' || (key in object);
} else {
result = customizer ? customizer(objValue, srcValue, key) : undefined;
if (typeof result == 'undefined') {
result = baseIsEqual(srcValue, objValue, customizer, true);
if (noCustomizer && data[2]) {
if (objValue === undefined && !(key in object)) {
return false;
}
} else {
var result = customizer ? customizer(objValue, srcValue, key) : undefined;
if (!(result === undefined ? baseIsEqual(srcValue, objValue, customizer, true) : result)) {
return false;
}
}
if (!result) {
return false;
}
}
return true;

View File

@@ -1,4 +1,5 @@
var baseEach = require('./baseEach');
var baseEach = require('./baseEach'),
isArrayLike = require('./isArrayLike');
/**
* The base implementation of `_.map` without support for callback shorthands
@@ -10,9 +11,11 @@ var baseEach = require('./baseEach');
* @returns {Array} Returns the new mapped array.
*/
function baseMap(collection, iteratee) {
var result = [];
var index = -1,
result = isArrayLike(collection) ? Array(collection.length) : [];
baseEach(collection, function(value, key, collection) {
result.push(iteratee(value, key, collection));
result[++index] = iteratee(value, key, collection);
});
return result;
}

View File

@@ -1,7 +1,5 @@
var baseIsMatch = require('./baseIsMatch'),
constant = require('../utility/constant'),
isStrictComparable = require('./isStrictComparable'),
keys = require('../object/keys'),
getMatchData = require('./getMatchData'),
toObject = require('./toObject');
/**
@@ -12,33 +10,20 @@ var baseIsMatch = require('./baseIsMatch'),
* @returns {Function} Returns the new function.
*/
function baseMatches(source) {
var props = keys(source),
length = props.length;
var matchData = getMatchData(source);
if (matchData.length == 1 && matchData[0][2]) {
var key = matchData[0][0],
value = matchData[0][1];
if (!length) {
return constant(true);
}
if (length == 1) {
var key = props[0],
value = source[key];
if (isStrictComparable(value)) {
return function(object) {
return object != null && object[key] === value &&
(typeof value != 'undefined' || (key in toObject(object)));
};
}
}
var values = Array(length),
strictCompareFlags = Array(length);
while (length--) {
value = source[props[length]];
values[length] = value;
strictCompareFlags[length] = isStrictComparable(value);
return function(object) {
if (object == null) {
return false;
}
return object[key] === value && (value !== undefined || (key in toObject(object)));
};
}
return function(object) {
return object != null && baseIsMatch(toObject(object), props, values, strictCompareFlags);
return baseIsMatch(object, matchData);
};
}

View File

@@ -1,25 +1,44 @@
var baseIsEqual = require('./baseIsEqual'),
var baseGet = require('./baseGet'),
baseIsEqual = require('./baseIsEqual'),
baseSlice = require('./baseSlice'),
isArray = require('../lang/isArray'),
isKey = require('./isKey'),
isStrictComparable = require('./isStrictComparable'),
toObject = require('./toObject');
last = require('../array/last'),
toObject = require('./toObject'),
toPath = require('./toPath');
/**
* The base implementation of `_.matchesProperty` which does not coerce `key`
* to a string.
* The base implementation of `_.matchesProperty` which does not clone `srcValue`.
*
* @private
* @param {string} key The key of the property to get.
* @param {*} value The value to compare.
* @param {string} path The path of the property to get.
* @param {*} srcValue The value to compare.
* @returns {Function} Returns the new function.
*/
function baseMatchesProperty(key, value) {
if (isStrictComparable(value)) {
return function(object) {
return object != null && object[key] === value &&
(typeof value != 'undefined' || (key in toObject(object)));
};
}
function baseMatchesProperty(path, srcValue) {
var isArr = isArray(path),
isCommon = isKey(path) && isStrictComparable(srcValue),
pathKey = (path + '');
path = toPath(path);
return function(object) {
return object != null && baseIsEqual(value, object[key], null, true);
if (object == null) {
return false;
}
var key = pathKey;
object = toObject(object);
if ((isArr || !isCommon) && !(key in object)) {
object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
if (object == null) {
return false;
}
key = last(path);
object = toObject(object);
}
return object[key] === srcValue
? (srcValue !== undefined || (key in object))
: baseIsEqual(srcValue, object[key], undefined, true);
};
}

View File

@@ -1,11 +1,11 @@
var arrayEach = require('./arrayEach'),
baseForOwn = require('./baseForOwn'),
baseMergeDeep = require('./baseMergeDeep'),
isArray = require('../lang/isArray'),
isLength = require('./isLength'),
isArrayLike = require('./isArrayLike'),
isObject = require('../lang/isObject'),
isObjectLike = require('./isObjectLike'),
isTypedArray = require('../lang/isTypedArray');
isTypedArray = require('../lang/isTypedArray'),
keys = require('../object/keys');
/**
* The base implementation of `_.merge` without support for argument juggling,
@@ -17,29 +17,37 @@ var arrayEach = require('./arrayEach'),
* @param {Function} [customizer] The function to customize merging properties.
* @param {Array} [stackA=[]] Tracks traversed source objects.
* @param {Array} [stackB=[]] Associates values with source counterparts.
* @returns {Object} Returns the destination object.
* @returns {Object} Returns `object`.
*/
function baseMerge(object, source, customizer, stackA, stackB) {
if (!isObject(object)) {
return object;
}
var isSrcArr = isLength(source.length) && (isArray(source) || isTypedArray(source));
(isSrcArr ? arrayEach : baseForOwn)(source, function(srcValue, key, source) {
var isSrcArr = isArrayLike(source) && (isArray(source) || isTypedArray(source)),
props = isSrcArr ? null : keys(source);
arrayEach(props || source, function(srcValue, key) {
if (props) {
key = srcValue;
srcValue = source[key];
}
if (isObjectLike(srcValue)) {
stackA || (stackA = []);
stackB || (stackB = []);
return baseMergeDeep(object, source, key, baseMerge, customizer, stackA, stackB);
baseMergeDeep(object, source, key, baseMerge, customizer, stackA, stackB);
}
var value = object[key],
result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
isCommon = typeof result == 'undefined';
else {
var value = object[key],
result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
isCommon = result === undefined;
if (isCommon) {
result = srcValue;
}
if ((isSrcArr || typeof result != 'undefined') &&
(isCommon || (result === result ? (result !== value) : (value === value)))) {
object[key] = result;
if (isCommon) {
result = srcValue;
}
if ((result !== undefined || (isSrcArr && !(key in object))) &&
(isCommon || (result === result ? (result !== value) : (value === value)))) {
object[key] = result;
}
}
});
return object;

View File

@@ -1,7 +1,7 @@
var arrayCopy = require('./arrayCopy'),
isArguments = require('../lang/isArguments'),
isArray = require('../lang/isArray'),
isLength = require('./isLength'),
isArrayLike = require('./isArrayLike'),
isPlainObject = require('../lang/isPlainObject'),
isTypedArray = require('../lang/isTypedArray'),
toPlainObject = require('../lang/toPlainObject');
@@ -33,14 +33,14 @@ function baseMergeDeep(object, source, key, mergeFunc, customizer, stackA, stack
}
var value = object[key],
result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
isCommon = typeof result == 'undefined';
isCommon = result === undefined;
if (isCommon) {
result = srcValue;
if (isLength(srcValue.length) && (isArray(srcValue) || isTypedArray(srcValue))) {
if (isArrayLike(srcValue) && (isArray(srcValue) || isTypedArray(srcValue))) {
result = isArray(value)
? value
: ((value && value.length) ? arrayCopy(value) : []);
: (isArrayLike(value) ? arrayCopy(value) : []);
}
else if (isPlainObject(srcValue) || isArguments(srcValue)) {
result = isArguments(value)

View File

@@ -1,5 +1,5 @@
/**
* The base implementation of `_.property` which does not coerce `key` to a string.
* The base implementation of `_.property` without support for deep paths.
*
* @private
* @param {string} key The key of the property to get.

View File

@@ -0,0 +1,19 @@
var baseGet = require('./baseGet'),
toPath = require('./toPath');
/**
* A specialized version of `baseProperty` which supports deep paths.
*
* @private
* @param {Array|string} path The path of the property to get.
* @returns {Function} Returns the new function.
*/
function basePropertyDeep(path) {
var pathKey = (path + '');
path = toPath(path);
return function(object) {
return baseGet(object, path, pathKey);
};
}
module.exports = basePropertyDeep;

30
internal/basePullAt.js Normal file
View File

@@ -0,0 +1,30 @@
var isIndex = require('./isIndex');
/** Used for native method references. */
var arrayProto = Array.prototype;
/** Native method references. */
var splice = arrayProto.splice;
/**
* The base implementation of `_.pullAt` without support for individual
* index arguments and capturing the removed elements.
*
* @private
* @param {Array} array The array to modify.
* @param {number[]} indexes The indexes of elements to remove.
* @returns {Array} Returns `array`.
*/
function basePullAt(array, indexes) {
var length = array ? indexes.length : 0;
while (length--) {
var index = indexes[length];
if (index != previous && isIndex(index)) {
var previous = index;
splice.call(array, index, 1);
}
}
return array;
}
module.exports = basePullAt;

View File

@@ -15,7 +15,7 @@ function baseSlice(array, start, end) {
if (start < 0) {
start = -start > length ? 0 : (length + start);
}
end = (typeof end == 'undefined' || end > length) ? length : (+end || 0);
end = (end === undefined || end > length) ? length : (+end || 0);
if (end < 0) {
end += length;
}

View File

@@ -1,30 +1,26 @@
var baseEach = require('./baseEach'),
var arrayMap = require('./arrayMap'),
baseCallback = require('./baseCallback'),
baseMap = require('./baseMap'),
baseSortBy = require('./baseSortBy'),
compareMultiple = require('./compareMultiple'),
isLength = require('./isLength');
compareMultiple = require('./compareMultiple');
/**
* The base implementation of `_.sortByOrder` without param guards.
*
* @private
* @param {Array|Object|string} collection The collection to iterate over.
* @param {string[]} props The property names to sort by.
* @param {boolean[]} orders The sort orders of `props`.
* @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
* @param {boolean[]} orders The sort orders of `iteratees`.
* @returns {Array} Returns the new sorted array.
*/
function baseSortByOrder(collection, props, orders) {
var index = -1,
length = collection.length,
result = isLength(length) ? Array(length) : [];
function baseSortByOrder(collection, iteratees, orders) {
var index = -1;
baseEach(collection, function(value) {
var length = props.length,
criteria = Array(length);
iteratees = arrayMap(iteratees, function(iteratee) { return baseCallback(iteratee); });
while (length--) {
criteria[length] = value == null ? undefined : value[props[length]];
}
result[++index] = { 'criteria': criteria, 'index': index, 'value': value };
var result = baseMap(collection, function(value) {
var criteria = arrayMap(iteratees, function(iteratee) { return iteratee(value); });
return { 'criteria': criteria, 'index': ++index, 'value': value };
});
return baseSortBy(result, function(object, other) {

View File

@@ -1,5 +1,5 @@
/**
* Converts `value` to a string if it is not one. An empty string is returned
* Converts `value` to a string if it's not one. An empty string is returned
* for `null` or `undefined` values.
*
* @private

View File

@@ -1,7 +1,7 @@
/**
* The base implementation of `_.values` and `_.valuesIn` which creates an
* array of `object` property values corresponding to the property names
* returned by `keysFunc`.
* of `props`.
*
* @private
* @param {Object} object The object to query.

View File

@@ -2,7 +2,7 @@ var binaryIndexBy = require('./binaryIndexBy'),
identity = require('../utility/identity');
/** Used as references for the maximum length and index of an array. */
var MAX_ARRAY_LENGTH = Math.pow(2, 32) - 1,
var MAX_ARRAY_LENGTH = 4294967295,
HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
/**
@@ -25,7 +25,7 @@ function binaryIndex(array, value, retHighest) {
var mid = (low + high) >>> 1,
computed = array[mid];
if (retHighest ? (computed <= value) : (computed < value)) {
if ((retHighest ? (computed <= value) : (computed < value)) && computed !== null) {
low = mid + 1;
} else {
high = mid;

View File

@@ -5,8 +5,8 @@ var floor = Math.floor;
var nativeMin = Math.min;
/** Used as references for the maximum length and index of an array. */
var MAX_ARRAY_LENGTH = Math.pow(2, 32) - 1,
MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1;
var MAX_ARRAY_LENGTH = 4294967295,
MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1;
/**
* This function is like `binaryIndex` except that it invokes `iteratee` for
@@ -27,17 +27,23 @@ function binaryIndexBy(array, value, iteratee, retHighest) {
var low = 0,
high = array ? array.length : 0,
valIsNaN = value !== value,
valIsUndef = typeof value == 'undefined';
valIsNull = value === null,
valIsUndef = value === undefined;
while (low < high) {
var mid = floor((low + high) / 2),
computed = iteratee(array[mid]),
isDef = computed !== undefined,
isReflexive = computed === computed;
if (valIsNaN) {
var setLow = isReflexive || retHighest;
} else if (valIsNull) {
setLow = isReflexive && isDef && (retHighest || computed != null);
} else if (valIsUndef) {
setLow = isReflexive && (retHighest || typeof computed != 'undefined');
setLow = isReflexive && (retHighest || isDef);
} else if (computed == null) {
setLow = false;
} else {
setLow = retHighest ? (computed <= value) : (computed < value);
}

View File

@@ -14,7 +14,7 @@ function bindCallback(func, thisArg, argCount) {
if (typeof func != 'function') {
return identity;
}
if (typeof thisArg == 'undefined') {
if (thisArg === undefined) {
return func;
}
switch (argCount) {

View File

@@ -1,11 +1,11 @@
var constant = require('../utility/constant'),
isNative = require('../lang/isNative');
getNative = require('./getNative');
/** Native method references. */
var ArrayBuffer = isNative(ArrayBuffer = global.ArrayBuffer) && ArrayBuffer,
bufferSlice = isNative(bufferSlice = ArrayBuffer && new ArrayBuffer(0).slice) && bufferSlice,
var ArrayBuffer = getNative(global, 'ArrayBuffer'),
bufferSlice = getNative(ArrayBuffer && new ArrayBuffer(0), 'slice'),
floor = Math.floor,
Uint8Array = isNative(Uint8Array = global.Uint8Array) && Uint8Array;
Uint8Array = getNative(global, 'Uint8Array');
/** Used to clone array buffers. */
var Float64Array = (function() {
@@ -13,10 +13,10 @@ var Float64Array = (function() {
// where the array buffer's `byteLength` is not a multiple of the typed
// array's `BYTES_PER_ELEMENT`.
try {
var func = isNative(func = global.Float64Array) && func,
var func = getNative(global, 'Float64Array'),
result = new func(new ArrayBuffer(10), 0, 1) && func;
} catch(e) {}
return result;
return result || null;
}());
/** Used as the size, in bytes, of each `Float64Array` element. */

View File

@@ -1,12 +0,0 @@
/**
* Used by `_.max` and `_.min` as the default callback for string values.
*
* @private
* @param {string} string The string to inspect.
* @returns {number} Returns the code unit of the first character of the string.
*/
function charAtCallback(string) {
return string.charCodeAt(0);
}
module.exports = charAtCallback;

View File

@@ -4,7 +4,7 @@ var baseCompareAscending = require('./baseCompareAscending');
* Used by `_.sortByOrder` to compare multiple properties of each element
* in a collection and stable sort them in the following order:
*
* If orders is unspecified, sort in ascending order for all properties.
* If `orders` is unspecified, sort in ascending order for all properties.
* Otherwise, for each property, sort in ascending order if its corresponding value in
* orders is true, and descending order if false.
*

View File

@@ -23,12 +23,12 @@ function composeArgsRight(args, partials, holders) {
while (++argsIndex < argsLength) {
result[argsIndex] = args[argsIndex];
}
var pad = argsIndex;
var offset = argsIndex;
while (++rightIndex < rightLength) {
result[pad + rightIndex] = partials[rightIndex];
result[offset + rightIndex] = partials[rightIndex];
}
while (++holdersIndex < holdersLength) {
result[pad + holders[holdersIndex]] = args[argsIndex++];
result[offset + holders[holdersIndex]] = args[argsIndex++];
}
return result;
}

View File

@@ -1,5 +1,6 @@
var bindCallback = require('./bindCallback'),
isIterateeCall = require('./isIterateeCall');
isIterateeCall = require('./isIterateeCall'),
restParam = require('../function/restParam');
/**
* Creates a function that assigns properties of source object(s) to a given
@@ -12,38 +13,32 @@ var bindCallback = require('./bindCallback'),
* @returns {Function} Returns the new assigner function.
*/
function createAssigner(assigner) {
return function() {
var args = arguments,
length = args.length,
object = args[0];
return restParam(function(object, sources) {
var index = -1,
length = object == null ? 0 : sources.length,
customizer = length > 2 ? sources[length - 2] : undefined,
guard = length > 2 ? sources[2] : undefined,
thisArg = length > 1 ? sources[length - 1] : undefined;
if (length < 2 || object == null) {
return object;
}
var customizer = args[length - 2],
thisArg = args[length - 1],
guard = args[3];
if (length > 3 && typeof customizer == 'function') {
if (typeof customizer == 'function') {
customizer = bindCallback(customizer, thisArg, 5);
length -= 2;
} else {
customizer = (length > 2 && typeof thisArg == 'function') ? thisArg : null;
customizer = typeof thisArg == 'function' ? thisArg : undefined;
length -= (customizer ? 1 : 0);
}
if (guard && isIterateeCall(args[1], args[2], guard)) {
customizer = length == 3 ? null : customizer;
length = 2;
if (guard && isIterateeCall(sources[0], sources[1], guard)) {
customizer = length < 3 ? undefined : customizer;
length = 1;
}
var index = 0;
while (++index < length) {
var source = args[index];
var source = sources[index];
if (source) {
assigner(object, source, customizer);
}
}
return object;
};
});
}
module.exports = createAssigner;

View File

@@ -1,4 +1,5 @@
var isLength = require('./isLength'),
var getLength = require('./getLength'),
isLength = require('./isLength'),
toObject = require('./toObject');
/**
@@ -11,7 +12,7 @@ var isLength = require('./isLength'),
*/
function createBaseEach(eachFunc, fromRight) {
return function(collection, iteratee) {
var length = collection ? collection.length : 0;
var length = collection ? getLength(collection) : 0;
if (!isLength(length)) {
return eachFunc(collection, iteratee);
}

View File

@@ -1,12 +1,12 @@
var SetCache = require('./SetCache'),
constant = require('../utility/constant'),
isNative = require('../lang/isNative');
getNative = require('./getNative');
/** Native method references. */
var Set = isNative(Set = global.Set) && Set;
var Set = getNative(global, 'Set');
/* Native method references for those with the same name as other `lodash` methods. */
var nativeCreate = isNative(nativeCreate = Object.create) && nativeCreate;
var nativeCreate = getNative(Object, 'create');
/**
* Creates a `Set` cache object to optimize linear searches of large arrays.

View File

@@ -11,8 +11,20 @@ var baseCreate = require('./baseCreate'),
*/
function createCtorWrapper(Ctor) {
return function() {
// Use a `switch` statement to work with class constructors.
// See https://people.mozilla.org/~jorendorff/es6-draft.html#sec-ecmascript-function-objects-call-thisargument-argumentslist
// for more details.
var args = arguments;
switch (args.length) {
case 0: return new Ctor;
case 1: return new Ctor(args[0]);
case 2: return new Ctor(args[0], args[1]);
case 3: return new Ctor(args[0], args[1], args[2]);
case 4: return new Ctor(args[0], args[1], args[2], args[3]);
case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
}
var thisBinding = baseCreate(Ctor.prototype),
result = Ctor.apply(thisBinding, arguments);
result = Ctor.apply(thisBinding, args);
// Mimic the constructor's `return` behavior.
// See https://es5.github.io/#x13.2.2 for more details.

View File

@@ -1,37 +1,31 @@
var baseCallback = require('./baseCallback'),
charAtCallback = require('./charAtCallback'),
extremumBy = require('./extremumBy'),
isArray = require('../lang/isArray'),
var arrayExtremum = require('./arrayExtremum'),
baseCallback = require('./baseCallback'),
baseExtremum = require('./baseExtremum'),
isIterateeCall = require('./isIterateeCall'),
isString = require('../lang/isString'),
toIterable = require('./toIterable');
/**
* Creates a `_.max` or `_.min` function.
*
* @private
* @param {Function} arrayFunc The function to get the extremum value from an array.
* @param {boolean} [isMin] Specify returning the minimum, instead of the maximum,
* extremum value.
* @param {Function} comparator The function used to compare values.
* @param {*} exValue The initial extremum value.
* @returns {Function} Returns the new extremum function.
*/
function createExtremum(arrayFunc, isMin) {
function createExtremum(comparator, exValue) {
return function(collection, iteratee, thisArg) {
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
iteratee = null;
}
var noIteratee = iteratee == null;
iteratee = noIteratee ? iteratee : baseCallback(iteratee, thisArg, 3);
if (noIteratee) {
var isArr = isArray(collection);
if (!isArr && isString(collection)) {
iteratee = charAtCallback;
} else {
return arrayFunc(isArr ? collection : toIterable(collection));
iteratee = baseCallback(iteratee, thisArg, 3);
if (iteratee.length == 1) {
collection = toIterable(collection);
var result = arrayExtremum(collection, iteratee, comparator, exValue);
if (!(collection.length && result === exValue)) {
return result;
}
}
return extremumBy(collection, iteratee, isMin);
return baseExtremum(collection, iteratee, comparator, exValue);
};
}

View File

@@ -19,7 +19,7 @@ function createFind(eachFunc, fromRight) {
return index > -1 ? collection[index] : undefined;
}
return baseFind(collection, predicate, eachFunc);
}
};
}
module.exports = createFind;

View File

@@ -4,6 +4,12 @@ var LodashWrapper = require('./LodashWrapper'),
isArray = require('../lang/isArray'),
isLaziable = require('./isLaziable');
/** Used to compose bitmasks for wrapper metadata. */
var CURRY_FLAG = 8,
PARTIAL_FLAG = 32,
ARY_FLAG = 128,
REARG_FLAG = 256;
/** Used as the `TypeError` message for "Functions" methods. */
var FUNC_ERROR_TEXT = 'Expected a function';
@@ -16,11 +22,8 @@ var FUNC_ERROR_TEXT = 'Expected a function';
*/
function createFlow(fromRight) {
return function() {
var length = arguments.length;
if (!length) {
return function() { return arguments[0]; };
}
var wrapper,
length = arguments.length,
index = fromRight ? length : -1,
leftIndex = 0,
funcs = Array(length);
@@ -30,16 +33,18 @@ function createFlow(fromRight) {
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
}
var funcName = wrapper ? '' : getFuncName(func);
wrapper = funcName == 'wrapper' ? new LodashWrapper([]) : wrapper;
if (!wrapper && LodashWrapper.prototype.thru && getFuncName(func) == 'wrapper') {
wrapper = new LodashWrapper([]);
}
}
index = wrapper ? -1 : length;
while (++index < length) {
func = funcs[index];
funcName = getFuncName(func);
var data = funcName == 'wrapper' ? getData(func) : null;
if (data && isLaziable(data[0])) {
var funcName = getFuncName(func),
data = funcName == 'wrapper' ? getData(func) : null;
if (data && isLaziable(data[0]) && data[1] == (ARY_FLAG | CURRY_FLAG | PARTIAL_FLAG | REARG_FLAG) && !data[4].length && data[9] == 1) {
wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
} else {
wrapper = (func.length == 1 && isLaziable(func)) ? wrapper[funcName]() : wrapper.thru(func);
@@ -51,7 +56,7 @@ function createFlow(fromRight) {
return wrapper.plant(args[0]).value();
}
var index = 0,
result = funcs[index].apply(this, args);
result = length ? funcs[index].apply(this, args) : args[0];
while (++index < length) {
result = funcs[index].call(this, result);

View File

@@ -11,7 +11,7 @@ var bindCallback = require('./bindCallback'),
*/
function createForEach(arrayFunc, eachFunc) {
return function(collection, iteratee, thisArg) {
return (typeof iteratee == 'function' && typeof thisArg == 'undefined' && isArray(collection))
return (typeof iteratee == 'function' && thisArg === undefined && isArray(collection))
? arrayFunc(collection, iteratee)
: eachFunc(collection, bindCallback(iteratee, thisArg, 3));
};

View File

@@ -10,7 +10,7 @@ var bindCallback = require('./bindCallback'),
*/
function createForIn(objectFunc) {
return function(object, iteratee, thisArg) {
if (typeof iteratee != 'function' || typeof thisArg != 'undefined') {
if (typeof iteratee != 'function' || thisArg !== undefined) {
iteratee = bindCallback(iteratee, thisArg, 3);
}
return objectFunc(object, iteratee, keysIn);

View File

@@ -9,7 +9,7 @@ var bindCallback = require('./bindCallback');
*/
function createForOwn(objectFunc) {
return function(object, iteratee, thisArg) {
if (typeof iteratee != 'function' || typeof thisArg != 'undefined') {
if (typeof iteratee != 'function' || thisArg !== undefined) {
iteratee = bindCallback(iteratee, thisArg, 3);
}
return objectFunc(object, iteratee);

Some files were not shown because too many files have changed in this diff Show More