Use eq in more places.

This commit is contained in:
John-David Dalton
2015-12-25 21:59:55 -06:00
parent b1f6bc72f4
commit f8236c711f

200
lodash.js
View File

@@ -646,42 +646,6 @@
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
* `comparator` to determine the extremum value.
@@ -1038,64 +1002,6 @@
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.
*
@@ -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`.
*
@@ -2133,6 +2054,25 @@
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.
*
@@ -3564,7 +3504,7 @@
value = array[index],
computed = iteratee ? iteratee(value) : value;
if ((seen === seen ? (seen !== computed) : (computed === computed))) {
if (!eq(seen, computed)) {
seen = computed;
result[++resIndex] = value;
}
@@ -3870,6 +3810,64 @@
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`.
*
@@ -4938,8 +4936,7 @@
if (type == 'number'
? (isArrayLike(object) && isIndex(index, object.length))
: (type == 'string' && index in object)) {
var other = object[index];
return value === value ? (value === other) : (other !== other);
return eq(value, object[index]);
}
return false;
}
@@ -6274,8 +6271,7 @@
var length = array ? array.length : 0;
if (length) {
var index = baseSortedIndex(array, value);
if (index < length &&
(value === value ? (value === array[index]) : (array[index] !== array[index]))) {
if (index < length && eq(value, array[index])) {
return index;
}
}
@@ -6342,10 +6338,8 @@
function sortedLastIndexOf(array, value) {
var length = array ? array.length : 0;
if (length) {
var index = baseSortedIndex(array, value, true) - 1,
other = array[index];
if (value === value ? (value === other) : (other !== other)) {
var index = baseSortedIndex(array, value, true) - 1;
if (eq(value, array[index])) {
return index;
}
}