mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 10:57:49 +00:00
Adjust fromIndex and length coercions.
This commit is contained in:
68
dist/lodash.underscore.js
vendored
68
dist/lodash.underscore.js
vendored
@@ -159,7 +159,7 @@
|
||||
* @returns {number} Returns the index of the matched value, else `-1`.
|
||||
*/
|
||||
function baseIndexOf(array, value, fromIndex) {
|
||||
var index = (fromIndex | 0) - 1,
|
||||
var index = (+fromIndex || 0) - 1,
|
||||
length = array ? array.length : 0;
|
||||
|
||||
while (++index < length) {
|
||||
@@ -617,7 +617,7 @@
|
||||
* @returns {Array} Returns the new flattened array.
|
||||
*/
|
||||
function baseFlatten(array, isShallow, isStrict, fromIndex) {
|
||||
var index = (fromIndex | 0) - 1,
|
||||
var index = (+fromIndex || 0) - 1,
|
||||
length = array ? array.length : 0,
|
||||
result = [];
|
||||
|
||||
@@ -978,9 +978,9 @@
|
||||
callback = createCallback(callback, thisArg, 3);
|
||||
|
||||
var index = -1,
|
||||
length = (collection && collection.length) | 0;
|
||||
length = (length = collection && collection.length, length > -1 && length >>> 0);
|
||||
|
||||
if (length > 0) {
|
||||
if (length) {
|
||||
while (++index < length) {
|
||||
var value = collection[index];
|
||||
setter(result, value, callback(value, index, collection), collection);
|
||||
@@ -1346,7 +1346,7 @@
|
||||
function indexOf(array, value, fromIndex) {
|
||||
var length = array ? array.length : 0;
|
||||
if (typeof fromIndex == 'number') {
|
||||
fromIndex = (fromIndex < 0 ? nativeMax(0, length + fromIndex) : fromIndex) | 0;
|
||||
fromIndex = fromIndex < 0 ? nativeMax(0, length + fromIndex) : (fromIndex || 0);
|
||||
} else if (fromIndex) {
|
||||
var index = sortedIndex(array, value);
|
||||
return (length && array[index] === value) ? index : -1;
|
||||
@@ -1519,13 +1519,13 @@
|
||||
var index = -1,
|
||||
length = array ? array.length : 0;
|
||||
|
||||
start |= 0;
|
||||
start = +start || 0;
|
||||
if (start < 0) {
|
||||
start = nativeMax(length + start, 0);
|
||||
} else if (start > length) {
|
||||
start = length;
|
||||
}
|
||||
end = typeof end == 'undefined' ? length : (end | 0);
|
||||
end = typeof end == 'undefined' ? length : (+end || 0);
|
||||
if (end < 0) {
|
||||
end = nativeMax(length + end, 0);
|
||||
} else if (end > length) {
|
||||
@@ -1943,10 +1943,10 @@
|
||||
*/
|
||||
function contains(collection, target) {
|
||||
var indexOf = getIndexOf(),
|
||||
length = (collection && collection.length) | 0,
|
||||
length = (length = collection && collection.length, length > -1 && length >>> 0),
|
||||
result = false;
|
||||
|
||||
if (length > 0) {
|
||||
if (length) {
|
||||
return indexOf(collection, target) > -1;
|
||||
}
|
||||
baseEach(collection, function(value) {
|
||||
@@ -2039,9 +2039,9 @@
|
||||
|
||||
predicate = createCallback(predicate, thisArg, 3);
|
||||
var index = -1,
|
||||
length = (collection && collection.length) | 0;
|
||||
length = (length = collection && collection.length, length > -1 && length >>> 0);
|
||||
|
||||
if (length > 0) {
|
||||
if (length) {
|
||||
while (++index < length) {
|
||||
if (!predicate(collection[index], index, collection)) {
|
||||
return false;
|
||||
@@ -2100,9 +2100,9 @@
|
||||
|
||||
predicate = createCallback(predicate, thisArg, 3);
|
||||
var index = -1,
|
||||
length = (collection && collection.length) | 0;
|
||||
length = (length = collection && collection.length, length > -1 && length >>> 0);
|
||||
|
||||
if (length > 0) {
|
||||
if (length) {
|
||||
while (++index < length) {
|
||||
var value = collection[index];
|
||||
if (predicate(value, index, collection)) {
|
||||
@@ -2163,8 +2163,8 @@
|
||||
* // => { 'name': 'fred', 'age': 40, 'blocked': true }
|
||||
*/
|
||||
function find(collection, predicate, thisArg) {
|
||||
var length = (collection && collection.length) | 0;
|
||||
if (length > 0) {
|
||||
var length = (length = collection && collection.length, length > -1 && length >>> 0);
|
||||
if (length) {
|
||||
var index = findIndex(collection, predicate, thisArg);
|
||||
return index > -1 ? collection[index] : undefined;
|
||||
}
|
||||
@@ -2200,10 +2200,10 @@
|
||||
*/
|
||||
function forEach(collection, callback, thisArg) {
|
||||
var index = -1,
|
||||
length = (collection && collection.length) | 0;
|
||||
length = (length = collection && collection.length, length > -1 && length >>> 0);
|
||||
|
||||
callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3);
|
||||
if (length > 0) {
|
||||
if (length) {
|
||||
while (++index < length) {
|
||||
if (callback(collection[index], index, collection) === breakIndicator) {
|
||||
break;
|
||||
@@ -2327,8 +2327,8 @@
|
||||
var args = slice(arguments, 2),
|
||||
index = -1,
|
||||
isFunc = typeof methodName == 'function',
|
||||
length = (collection && collection.length) | 0,
|
||||
result = Array(length < 0 ? 0 : length);
|
||||
length = collection && collection.length,
|
||||
result = Array(length < 0 ? 0 : length >>> 0);
|
||||
|
||||
baseEach(collection, function(value) {
|
||||
result[++index] = (isFunc ? methodName : value[methodName]).apply(value, args);
|
||||
@@ -2377,10 +2377,10 @@
|
||||
*/
|
||||
function map(collection, callback, thisArg) {
|
||||
var index = -1,
|
||||
length = (collection && collection.length) | 0;
|
||||
length = (length = collection && collection.length, length > -1 && length >>> 0);
|
||||
|
||||
callback = createCallback(callback, thisArg, 3);
|
||||
if (length > 0) {
|
||||
if (length) {
|
||||
var result = Array(length);
|
||||
while (++index < length) {
|
||||
result[index] = callback(collection[index], index, collection);
|
||||
@@ -2444,9 +2444,9 @@
|
||||
callback = null;
|
||||
}
|
||||
var index = -1,
|
||||
length = (collection && collection.length) | 0;
|
||||
length = (length = collection && collection.length, length > -1 && length >>> 0);
|
||||
|
||||
if (callback == null && length > 0) {
|
||||
if (callback == null && length) {
|
||||
while (++index < length) {
|
||||
var value = collection[index];
|
||||
if (value > result) {
|
||||
@@ -2517,9 +2517,9 @@
|
||||
callback = null;
|
||||
}
|
||||
var index = -1,
|
||||
length = (collection && collection.length) | 0;
|
||||
length = (length = collection && collection.length, length > -1 && length >>> 0);
|
||||
|
||||
if (callback == null && length > 0) {
|
||||
if (callback == null && length) {
|
||||
while (++index < length) {
|
||||
var value = collection[index];
|
||||
if (value < result) {
|
||||
@@ -2645,9 +2645,9 @@
|
||||
callback = createCallback(callback, thisArg, 4);
|
||||
|
||||
var index = -1,
|
||||
length = (collection && collection.length) | 0;
|
||||
length = (length = collection && collection.length, length > -1 && length >>> 0);
|
||||
|
||||
if (length > 0) {
|
||||
if (length) {
|
||||
if (noaccum && length) {
|
||||
accumulator = collection[++index];
|
||||
}
|
||||
@@ -2761,7 +2761,7 @@
|
||||
collection = values(collection);
|
||||
}
|
||||
if (n == null || guard) {
|
||||
var length = (collection && collection.length) | 0;
|
||||
var length = (length = collection && collection.length, length > -1 && length >>> 0);
|
||||
return length > 0 ? collection[baseRandom(0, length - 1)] : undefined;
|
||||
}
|
||||
var result = shuffle(collection);
|
||||
@@ -2786,8 +2786,8 @@
|
||||
*/
|
||||
function shuffle(collection) {
|
||||
var index = -1,
|
||||
length = (collection && collection.length) | 0,
|
||||
result = Array(length < 0 ? 0 : length);
|
||||
length = collection && collection.length,
|
||||
result = Array(length < 0 ? 0 : length >>> 0);
|
||||
|
||||
baseEach(collection, function(value) {
|
||||
var rand = baseRandom(0, ++index);
|
||||
@@ -2870,9 +2870,9 @@
|
||||
|
||||
predicate = createCallback(predicate, thisArg, 3);
|
||||
var index = -1,
|
||||
length = (collection && collection.length) | 0;
|
||||
length = (length = collection && collection.length, length > -1 && length >>> 0);
|
||||
|
||||
if (length > 0) {
|
||||
if (length) {
|
||||
while (++index < length) {
|
||||
if (predicate(collection[index], index, collection)) {
|
||||
return true;
|
||||
@@ -2937,8 +2937,8 @@
|
||||
*/
|
||||
function sortBy(collection, callback, thisArg) {
|
||||
var index = -1,
|
||||
length = (collection && collection.length) | 0,
|
||||
result = Array(length < 0 ? 0 : length);
|
||||
length = collection && collection.length,
|
||||
result = Array(length < 0 ? 0 : length >>> 0);
|
||||
|
||||
callback = createCallback(callback, thisArg, 3);
|
||||
baseEach(collection, function(value, key, collection) {
|
||||
|
||||
Reference in New Issue
Block a user