From 14e62ae8d24ade984d67dba3b0955c6df3063c1d Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 16 Sep 2015 19:09:16 -0700 Subject: [PATCH] Make `_.isString` use `_.isArray` to reduce usage patterns. --- lodash.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lodash.js b/lodash.js index fb1168490..1e2480aed 100644 --- a/lodash.js +++ b/lodash.js @@ -6486,14 +6486,13 @@ */ function includes(collection, target, fromIndex, guard) { collection = isArrayLike(collection) ? collection : values(collection); + fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0; + var length = collection.length; - if (guard || !fromIndex) { - fromIndex = 0; - } else { - fromIndex = toInteger(fromIndex); - fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex; + if (fromIndex < 0) { + fromIndex = nativeMax(length + fromIndex, 0); } - return (typeof collection == 'string' || !isArray(collection) && isString(collection)) + return isString(collection) ? (fromIndex <= length && collection.indexOf(target, fromIndex) > -1) : (!!length && getIndexOf(collection, target, fromIndex) > -1); } @@ -6849,7 +6848,7 @@ } if (isArrayLike(collection)) { var result = collection.length; - return (result && !isArray(collection) && isString(collection)) + return (result && isString(collection)) ? stringSize(collection) : result; } @@ -8929,7 +8928,8 @@ * // => false */ function isString(value) { - return typeof value == 'string' || (isObjectLike(value) && objToString.call(value) == stringTag); + return typeof value == 'string' || + (!isArray(value) && isObjectLike(value) && objToString.call(value) == stringTag); } /** @@ -9040,7 +9040,7 @@ return []; } if (isArrayLike(value)) { - return (!isArray(value) && isString(value)) ? stringToArray(value) : copyArray(value); + return isString(value) ? stringToArray(value) : copyArray(value); } if (iteratorSymbol && value[iteratorSymbol]) { return iteratorToArray(value[iteratorSymbol]());