Change strict equality matches to SameValueZero matches.

This commit is contained in:
John-David Dalton
2014-07-31 17:25:58 -07:00
parent 5cbc44610c
commit d2870b6df7

View File

@@ -350,10 +350,12 @@
*/ */
function baseIndexOf(array, value, fromIndex) { function baseIndexOf(array, value, fromIndex) {
var index = (fromIndex || 0) - 1, var index = (fromIndex || 0) - 1,
length = array ? array.length : 0; length = array ? array.length : 0,
nans = value !== value;
while (++index < length) { while (++index < length) {
if (array[index] === value) { var other = array[index];
if (other === value || (nans && other !== other)) {
return index; return index;
} }
} }
@@ -1657,7 +1659,7 @@
while (++index < length) { while (++index < length) {
var value = array[index]; var value = array[index];
if (isCommon) { if (isCommon && value === value) {
var valuesIndex = valuesLength; var valuesIndex = valuesLength;
while (valuesIndex--) { while (valuesIndex--) {
if (values[valuesIndex] === value) { if (values[valuesIndex] === value) {
@@ -2449,7 +2451,7 @@
var value = array[index], var value = array[index],
computed = iterator ? iterator(value, index, array) : value; computed = iterator ? iterator(value, index, array) : value;
if (isCommon) { if (isCommon && value === value) {
var seenIndex = seen.length; var seenIndex = seen.length;
while (seenIndex--) { while (seenIndex--) {
if (seen[seenIndex] === computed) { if (seen[seenIndex] === computed) {
@@ -3184,8 +3186,12 @@
} }
/** /**
* Creates an array excluding all values of the provided arrays using strict * Creates an array excluding all values of the provided arrays using
* equality for comparisons, i.e. `===`. * `SameValueZero` for equality comparisons.
*
* Note: `SameValueZero` is like strict equality, e.g. `===`, except that
* `NaN` matches `NaN`. See the [ES6 spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* for more details.
* *
* @static * @static
* @memberOf _ * @memberOf _
@@ -3552,10 +3558,14 @@
/** /**
* Gets the index at which the first occurrence of `value` is found in `array` * Gets the index at which the first occurrence of `value` is found in `array`
* using strict equality for comparisons, i.e. `===`. If `fromIndex` is negative, * using `SameValueZero` for equality comparisons. If `fromIndex` is negative,
* it is used as the offset from the end of the collection. If `array` is * it is used as the offset from the end of the collection. If `array` is
* sorted providing `true` for `fromIndex` performs a faster binary search. * sorted providing `true` for `fromIndex` performs a faster binary search.
* *
* Note: `SameValueZero` is like strict equality, e.g. `===`, except that
* `NaN` matches `NaN`. See the [ES6 spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* for more details.
*
* @static * @static
* @memberOf _ * @memberOf _
* @category Array * @category Array
@@ -3609,7 +3619,11 @@
/** /**
* Creates an array of unique values present in all provided arrays using * Creates an array of unique values present in all provided arrays using
* strict equality for comparisons, i.e. `===`. * `SameValueZero` for equality comparisons.
*
* Note: `SameValueZero` is like strict equality, e.g. `===`, except that
* `NaN` matches `NaN`. See the [ES6 spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* for more details.
* *
* @static * @static
* @memberOf _ * @memberOf _
@@ -3717,8 +3731,10 @@
index = sortedLastIndex(array, value) - 1; index = sortedLastIndex(array, value) - 1;
return (length && array[index] === value) ? index : -1; return (length && array[index] === value) ? index : -1;
} }
var nans = value !== value;
while (index--) { while (index--) {
if (array[index] === value) { var other = array[index];
if (other === value || (nans && other !== other)) {
return index; return index;
} }
} }
@@ -3726,11 +3742,15 @@
} }
/** /**
* Removes all provided values from `array` using strict equality for * Removes all provided values from `array` using `SameValueZero` for equality
* comparisons, i.e. `===`. * comparisons.
* *
* Note: Unlike `_.without`, this method mutates `array`. * Note: Unlike `_.without`, this method mutates `array`.
* *
* `SameValueZero` is like strict equality, e.g. `===`, except that `NaN` matches
* `NaN`. See the [ES6 spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* for more details.
*
* @static * @static
* @memberOf _ * @memberOf _
* @category Array * @category Array
@@ -3747,17 +3767,14 @@
function pull(array) { function pull(array) {
var argsIndex = 0, var argsIndex = 0,
argsLength = arguments.length, argsLength = arguments.length,
length = array ? array.length : 0; indexOf = getIndexOf();
while (++argsIndex < argsLength) { while (++argsIndex < argsLength) {
var index = -1, var fromIndex = 0,
value = arguments[argsIndex]; value = arguments[argsIndex];
while (++index < length) { while ((fromIndex = indexOf(array, value, fromIndex)) > -1) {
if (array[index] === value) { splice.call(array, fromIndex, 1);
splice.call(array, index--, 1);
length--;
}
} }
} }
return array; return array;
@@ -4134,7 +4151,11 @@
/** /**
* Creates an array of unique values, in order, of the provided arrays using * Creates an array of unique values, in order, of the provided arrays using
* strict equality for comparisons, i.e. `===`. * `SameValueZero` for equality comparisons.
*
* Note: `SameValueZero` is like strict equality, e.g. `===`, except that
* `NaN` matches `NaN`. See the [ES6 spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* for more details.
* *
* @static * @static
* @memberOf _ * @memberOf _
@@ -4151,12 +4172,12 @@
} }
/** /**
* Creates a duplicate-value-free version of an array using strict equality * Creates a duplicate-value-free version of an array using `SameValueZero`
* for comparisons, i.e. `===`. Providing `true` for `isSorted` performs a * for equality comparisons. Providing `true` for `isSorted` performs a faster
* faster search algorithm for sorted arrays. If an iterator function is * search algorithm for sorted arrays. If an iterator function is provided it
* provided it is executed for each value in the array to generate the criterion * is executed for each value in the array to generate the criterion by which
* by which uniqueness is computed. The `iterator` is bound to `thisArg` and * uniqueness is computed. The `iterator` is bound to `thisArg` and invoked
* invoked with three arguments; (value, index, array). * with three arguments; (value, index, array).
* *
* If a property name is provided for `iterator` the created "_.pluck" style * If a property name is provided for `iterator` the created "_.pluck" style
* callback returns the property value of the given element. * callback returns the property value of the given element.
@@ -4165,6 +4186,10 @@
* returns `true` for elements that have the properties of the given object, * returns `true` for elements that have the properties of the given object,
* else `false`. * else `false`.
* *
* Note: `SameValueZero` is like strict equality, e.g. `===`, except that
* `NaN` matches `NaN`. See the [ES6 spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* for more details.
*
* @static * @static
* @memberOf _ * @memberOf _
* @alias unique * @alias unique
@@ -4248,8 +4273,12 @@
} }
/** /**
* Creates an array excluding all provided values using strict equality for * Creates an array excluding all provided values using `SameValueZero` for
* comparisons, i.e. `===`. * equality comparisons.
*
* Note: `SameValueZero` is like strict equality, e.g. `===`, except that
* `NaN` matches `NaN`. See the [ES6 spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* for more details.
* *
* @static * @static
* @memberOf _ * @memberOf _
@@ -4507,9 +4536,13 @@
} }
/** /**
* Checks if `value` is present in `collection` using strict equality for * Checks if `value` is present in `collection` using `SameValueZero` for
* comparisons, i.e. `===`. If `fromIndex` is negative, it is used as the * equality comparisons. If `fromIndex` is negative, it is used as the offset
* offset from the end of the collection. * from the end of the collection.
*
* Note: `SameValueZero` is like strict equality, e.g. `===`, except that
* `NaN` matches `NaN`. See the [ES6 spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* for more details.
* *
* @static * @static
* @memberOf _ * @memberOf _