mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 03:17:49 +00:00
Use eq in more places.
This commit is contained in:
200
lodash.js
200
lodash.js
@@ -646,42 +646,6 @@
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Assigns `value` to `key` of `object` if the existing value is not equivalent
|
|
||||||
* using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
|
||||||
* for equality comparisons.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {Object} object The object to modify.
|
|
||||||
* @param {string} key The key of the property to assign.
|
|
||||||
* @param {*} value The value to assign.
|
|
||||||
*/
|
|
||||||
function assignValue(object, key, value) {
|
|
||||||
var oldValue = object[key];
|
|
||||||
if ((value === value ? (value !== oldValue) : (oldValue === oldValue)) ||
|
|
||||||
(value === undefined && !(key in object))) {
|
|
||||||
object[key] = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This function is like `assignValue` except that it doesn't assign `undefined` values.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {Object} object The object to modify.
|
|
||||||
* @param {string} key The key of the property to assign.
|
|
||||||
* @param {*} value The value to assign.
|
|
||||||
*/
|
|
||||||
function assignMergeValue(object, key, value) {
|
|
||||||
var oldValue = object[key];
|
|
||||||
if ((value !== undefined &&
|
|
||||||
(value === value ? (value !== oldValue) : (oldValue === oldValue))) ||
|
|
||||||
(typeof key == 'number' &&
|
|
||||||
value === undefined && !(key in object))) {
|
|
||||||
object[key] = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base implementation of methods like `_.max` and `_.min` which accepts a
|
* The base implementation of methods like `_.max` and `_.min` which accepts a
|
||||||
* `comparator` to determine the extremum value.
|
* `comparator` to determine the extremum value.
|
||||||
@@ -1038,64 +1002,6 @@
|
|||||||
return object.index - other.index;
|
return object.index - other.index;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Copies the values of `source` to `array`.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {Array} source The array to copy values from.
|
|
||||||
* @param {Array} [array=[]] The array to copy values to.
|
|
||||||
* @returns {Array} Returns `array`.
|
|
||||||
*/
|
|
||||||
function copyArray(source, array) {
|
|
||||||
var index = -1,
|
|
||||||
length = source.length;
|
|
||||||
|
|
||||||
array || (array = Array(length));
|
|
||||||
while (++index < length) {
|
|
||||||
array[index] = source[index];
|
|
||||||
}
|
|
||||||
return array;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copies properties of `source` to `object`.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {Object} source The object to copy properties from.
|
|
||||||
* @param {Array} props The property names to copy.
|
|
||||||
* @param {Object} [object={}] The object to copy properties to.
|
|
||||||
* @returns {Object} Returns `object`.
|
|
||||||
*/
|
|
||||||
function copyObject(source, props, object) {
|
|
||||||
return copyObjectWith(source, props, object);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This function is like `copyObject` except that it accepts a function to
|
|
||||||
* customize copied values.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {Object} source The object to copy properties from.
|
|
||||||
* @param {Array} props The property names to copy.
|
|
||||||
* @param {Object} [object={}] The object to copy properties to.
|
|
||||||
* @param {Function} [customizer] The function to customize copied values.
|
|
||||||
* @returns {Object} Returns `object`.
|
|
||||||
*/
|
|
||||||
function copyObjectWith(source, props, object, customizer) {
|
|
||||||
object || (object = {});
|
|
||||||
|
|
||||||
var index = -1,
|
|
||||||
length = props.length;
|
|
||||||
|
|
||||||
while (++index < length) {
|
|
||||||
var key = props[index],
|
|
||||||
newValue = customizer ? customizer(object[key], source[key], key, object, source) : source[key];
|
|
||||||
|
|
||||||
assignValue(object, key, newValue);
|
|
||||||
}
|
|
||||||
return object;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used by `_.deburr` to convert latin-1 supplementary letters to basic latin letters.
|
* Used by `_.deburr` to convert latin-1 supplementary letters to basic latin letters.
|
||||||
*
|
*
|
||||||
@@ -2113,6 +2019,21 @@
|
|||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function is like `assignValue` except that it doesn't assign `undefined` values.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {Object} object The object to modify.
|
||||||
|
* @param {string} key The key of the property to assign.
|
||||||
|
* @param {*} value The value to assign.
|
||||||
|
*/
|
||||||
|
function assignMergeValue(object, key, value) {
|
||||||
|
if ((value !== undefined && !eq(value, object[key])) ||
|
||||||
|
(typeof key == 'number' && value === undefined && !(key in object))) {
|
||||||
|
object[key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assigns own symbol properties of `source` to `object`.
|
* Assigns own symbol properties of `source` to `object`.
|
||||||
*
|
*
|
||||||
@@ -2133,6 +2054,25 @@
|
|||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assigns `value` to `key` of `object` if the existing value is not equivalent
|
||||||
|
* using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
||||||
|
* for equality comparisons.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {Object} object The object to modify.
|
||||||
|
* @param {string} key The key of the property to assign.
|
||||||
|
* @param {*} value The value to assign.
|
||||||
|
*/
|
||||||
|
function assignValue(object, key, value) {
|
||||||
|
var oldValue = object[key];
|
||||||
|
if ((!eq(value, oldValue) ||
|
||||||
|
(eq(oldValue, objectProto[key]) && !hasOwnProperty.call(object, key))) ||
|
||||||
|
(value === undefined && !(key in object))) {
|
||||||
|
object[key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes `key` and its value from the associative array.
|
* Removes `key` and its value from the associative array.
|
||||||
*
|
*
|
||||||
@@ -3564,7 +3504,7 @@
|
|||||||
value = array[index],
|
value = array[index],
|
||||||
computed = iteratee ? iteratee(value) : value;
|
computed = iteratee ? iteratee(value) : value;
|
||||||
|
|
||||||
if ((seen === seen ? (seen !== computed) : (computed === computed))) {
|
if (!eq(seen, computed)) {
|
||||||
seen = computed;
|
seen = computed;
|
||||||
result[++resIndex] = value;
|
result[++resIndex] = value;
|
||||||
}
|
}
|
||||||
@@ -3870,6 +3810,64 @@
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies the values of `source` to `array`.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {Array} source The array to copy values from.
|
||||||
|
* @param {Array} [array=[]] The array to copy values to.
|
||||||
|
* @returns {Array} Returns `array`.
|
||||||
|
*/
|
||||||
|
function copyArray(source, array) {
|
||||||
|
var index = -1,
|
||||||
|
length = source.length;
|
||||||
|
|
||||||
|
array || (array = Array(length));
|
||||||
|
while (++index < length) {
|
||||||
|
array[index] = source[index];
|
||||||
|
}
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies properties of `source` to `object`.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {Object} source The object to copy properties from.
|
||||||
|
* @param {Array} props The property names to copy.
|
||||||
|
* @param {Object} [object={}] The object to copy properties to.
|
||||||
|
* @returns {Object} Returns `object`.
|
||||||
|
*/
|
||||||
|
function copyObject(source, props, object) {
|
||||||
|
return copyObjectWith(source, props, object);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function is like `copyObject` except that it accepts a function to
|
||||||
|
* customize copied values.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {Object} source The object to copy properties from.
|
||||||
|
* @param {Array} props The property names to copy.
|
||||||
|
* @param {Object} [object={}] The object to copy properties to.
|
||||||
|
* @param {Function} [customizer] The function to customize copied values.
|
||||||
|
* @returns {Object} Returns `object`.
|
||||||
|
*/
|
||||||
|
function copyObjectWith(source, props, object, customizer) {
|
||||||
|
object || (object = {});
|
||||||
|
|
||||||
|
var index = -1,
|
||||||
|
length = props.length;
|
||||||
|
|
||||||
|
while (++index < length) {
|
||||||
|
var key = props[index],
|
||||||
|
newValue = customizer ? customizer(object[key], source[key], key, object, source) : source[key];
|
||||||
|
|
||||||
|
assignValue(object, key, newValue);
|
||||||
|
}
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a function like `_.groupBy`.
|
* Creates a function like `_.groupBy`.
|
||||||
*
|
*
|
||||||
@@ -4938,8 +4936,7 @@
|
|||||||
if (type == 'number'
|
if (type == 'number'
|
||||||
? (isArrayLike(object) && isIndex(index, object.length))
|
? (isArrayLike(object) && isIndex(index, object.length))
|
||||||
: (type == 'string' && index in object)) {
|
: (type == 'string' && index in object)) {
|
||||||
var other = object[index];
|
return eq(value, object[index]);
|
||||||
return value === value ? (value === other) : (other !== other);
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -6274,8 +6271,7 @@
|
|||||||
var length = array ? array.length : 0;
|
var length = array ? array.length : 0;
|
||||||
if (length) {
|
if (length) {
|
||||||
var index = baseSortedIndex(array, value);
|
var index = baseSortedIndex(array, value);
|
||||||
if (index < length &&
|
if (index < length && eq(value, array[index])) {
|
||||||
(value === value ? (value === array[index]) : (array[index] !== array[index]))) {
|
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6342,10 +6338,8 @@
|
|||||||
function sortedLastIndexOf(array, value) {
|
function sortedLastIndexOf(array, value) {
|
||||||
var length = array ? array.length : 0;
|
var length = array ? array.length : 0;
|
||||||
if (length) {
|
if (length) {
|
||||||
var index = baseSortedIndex(array, value, true) - 1,
|
var index = baseSortedIndex(array, value, true) - 1;
|
||||||
other = array[index];
|
if (eq(value, array[index])) {
|
||||||
|
|
||||||
if (value === value ? (value === other) : (other !== other)) {
|
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user