From d0f23b67ac279d493bbadb5f332abd5d6e86427e Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 28 Feb 2017 13:39:50 -0800 Subject: [PATCH] Use consistent nullish check for `array`. --- dropRightWhile.js | 2 +- dropWhile.js | 2 +- maxBy.js | 2 +- minBy.js | 2 +- nth.js | 2 +- pullAll.js | 2 +- pullAllBy.js | 2 +- pullAllWith.js | 2 +- remove.js | 2 +- sortedUniq.js | 2 +- sortedUniqBy.js | 2 +- sum.js | 2 +- sumBy.js | 2 +- take.js | 2 +- takeRightWhile.js | 2 +- takeWhile.js | 2 +- uniq.js | 2 +- uniqBy.js | 2 +- uniqWith.js | 2 +- unzip.js | 2 +- unzipWith.js | 2 +- 21 files changed, 21 insertions(+), 21 deletions(-) diff --git a/dropRightWhile.js b/dropRightWhile.js index ab2dd5f72..e209b70d3 100644 --- a/dropRightWhile.js +++ b/dropRightWhile.js @@ -22,7 +22,7 @@ import baseWhile from './.internal/baseWhile.js' * // => objects for ['barney'] */ function dropRightWhile(array, predicate) { - return (array && array.length) + return (array != null && array.length) ? baseWhile(array, predicate, true, true) : [] } diff --git a/dropWhile.js b/dropWhile.js index fc4fe43bc..88b7b6c8b 100644 --- a/dropWhile.js +++ b/dropWhile.js @@ -22,7 +22,7 @@ import baseWhile from './.internal/baseWhile.js' * // => objects for ['pebbles'] */ function dropWhile(array, predicate) { - return (array && array.length) + return (array != null && array.length) ? baseWhile(array, predicate, true) : [] } diff --git a/maxBy.js b/maxBy.js index 440f153d0..d28118165 100644 --- a/maxBy.js +++ b/maxBy.js @@ -20,7 +20,7 @@ import isSymbol from './isSymbol.js' function maxBy(array, iteratee) { let result let index = -1 - const length = array ? array.length : 0 + const length = array == null ? 0 : array.length while (++index < length) { let computed diff --git a/minBy.js b/minBy.js index 57355341d..045d38974 100644 --- a/minBy.js +++ b/minBy.js @@ -20,7 +20,7 @@ import isSymbol from './isSymbol.js' function minBy(array, iteratee) { let result let index = -1 - const length = array ? array.length : 0 + const length = array == null ? 0 : array.length while (++index < length) { let computed diff --git a/nth.js b/nth.js index 906b5633b..fc74ae6aa 100644 --- a/nth.js +++ b/nth.js @@ -21,7 +21,7 @@ import toInteger from './toInteger.js' * // => 'c' */ function nth(array, n) { - return (array && array.length) ? baseNth(array, toInteger(n)) : undefined + return (array != null && array.length) ? baseNth(array, toInteger(n)) : undefined } export default nth diff --git a/pullAll.js b/pullAll.js index 9dcb4da7a..1f320204b 100644 --- a/pullAll.js +++ b/pullAll.js @@ -20,7 +20,7 @@ import basePullAll from './.internal/basePullAll.js' * // => ['b', 'b'] */ function pullAll(array, values) { - return (array && array.length && values && values.length) + return (array != null && array.length && values != null && values.length) ? basePullAll(array, values) : array } diff --git a/pullAllBy.js b/pullAllBy.js index 09b98ecdb..863628d73 100644 --- a/pullAllBy.js +++ b/pullAllBy.js @@ -23,7 +23,7 @@ import basePullAll from './.internal/basePullAll.js' * // => [{ 'x': 2 }] */ function pullAllBy(array, values, iteratee) { - return (array && array.length && values && values.length) + return (array != null && array.length && values != null && values.length) ? basePullAll(array, values, iteratee) : array } diff --git a/pullAllWith.js b/pullAllWith.js index c8e426901..bd77c5849 100644 --- a/pullAllWith.js +++ b/pullAllWith.js @@ -23,7 +23,7 @@ import basePullAll from './.internal/basePullAll.js' * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }] */ function pullAllWith(array, values, comparator) { - return (array && array.length && values && values.length) + return (array != null && array.length && values != null && values.length) ? basePullAll(array, values, undefined, comparator) : array } diff --git a/remove.js b/remove.js index 91d8ab3fd..c7fb68a57 100644 --- a/remove.js +++ b/remove.js @@ -27,7 +27,7 @@ import basePullAt from './.internal/basePullAt.js' */ function remove(array, predicate) { const result = [] - if (!(array && array.length)) { + if (!(array != null && array.length)) { return result } let index = -1 diff --git a/sortedUniq.js b/sortedUniq.js index f2a426cfd..713f75ed6 100644 --- a/sortedUniq.js +++ b/sortedUniq.js @@ -14,7 +14,7 @@ import baseSortedUniq from './.internal/baseSortedUniq.js' * // => [1, 2] */ function sortedUniq(array) { - return (array && array.length) + return (array != null && array.length) ? baseSortedUniq(array) : [] } diff --git a/sortedUniqBy.js b/sortedUniqBy.js index 11684babd..32ca129c8 100644 --- a/sortedUniqBy.js +++ b/sortedUniqBy.js @@ -15,7 +15,7 @@ import baseSortedUniq from './.internal/baseSortedUniq.js' * // => [1.1, 2.3] */ function sortedUniqBy(array, iteratee) { - return (array && array.length) + return (array != null && array.length) ? baseSortedUniq(array, iteratee) : [] } diff --git a/sum.js b/sum.js index 15d64f2c4..d28629776 100644 --- a/sum.js +++ b/sum.js @@ -13,7 +13,7 @@ import baseSum from './.internal/baseSum.js' * // => 20 */ function sum(array) { - return (array && array.length) + return (array != null && array.length) ? baseSum(array, value => value) : 0 } diff --git a/sumBy.js b/sumBy.js index 1f92cf209..5775bf595 100644 --- a/sumBy.js +++ b/sumBy.js @@ -18,7 +18,7 @@ import baseSum from './.internal/baseSum.js' * // => 20 */ function sumBy(array, iteratee) { - return (array && array.length) + return (array != null && array.length) ? baseSum(array, iteratee) : 0 } diff --git a/take.js b/take.js index b9bdc4f83..a2247a1d8 100644 --- a/take.js +++ b/take.js @@ -25,7 +25,7 @@ import toInteger from './toInteger.js' * // => [] */ function take(array, n, guard) { - if (!(array && array.length)) { + if (!(array != null && array.length)) { return [] } n = (guard || n === undefined) ? 1 : toInteger(n) diff --git a/takeRightWhile.js b/takeRightWhile.js index 4d6c0e296..01cccbe13 100644 --- a/takeRightWhile.js +++ b/takeRightWhile.js @@ -22,7 +22,7 @@ import baseWhile from './.internal/baseWhile.js' * // => objects for ['fred', 'pebbles'] */ function takeRightWhile(array, predicate) { - return (array && array.length) + return (array != null && array.length) ? baseWhile(array, predicate, false, true) : [] } diff --git a/takeWhile.js b/takeWhile.js index 9ebfd811a..ec24da5ed 100644 --- a/takeWhile.js +++ b/takeWhile.js @@ -22,7 +22,7 @@ import baseWhile from './.internal/baseWhile.js' * // => objects for ['barney', 'fred'] */ function takeWhile(array, predicate) { - return (array && array.length) + return (array != null && array.length) ? baseWhile(array, predicate) : [] } diff --git a/uniq.js b/uniq.js index 58b99f5ad..6de091b4b 100644 --- a/uniq.js +++ b/uniq.js @@ -18,7 +18,7 @@ import baseUniq from './.internal/baseUniq.js' * // => [2, 1] */ function uniq(array) { - return (array && array.length) ? baseUniq(array) : [] + return (array != null && array.length) ? baseUniq(array) : [] } export default uniq diff --git a/uniqBy.js b/uniqBy.js index 7b6056fb9..b83f9b2b9 100644 --- a/uniqBy.js +++ b/uniqBy.js @@ -19,7 +19,7 @@ import baseUniq from './.internal/baseUniq.js' * // => [2.1, 1.2] */ function uniqBy(array, iteratee) { - return (array && array.length) ? baseUniq(array, iteratee) : [] + return (array != null && array.length) ? baseUniq(array, iteratee) : [] } export default uniqBy diff --git a/uniqWith.js b/uniqWith.js index 5bd9b3a01..e7f97ddc3 100644 --- a/uniqWith.js +++ b/uniqWith.js @@ -21,7 +21,7 @@ import baseUniq from './.internal/baseUniq.js' */ function uniqWith(array, comparator) { comparator = typeof comparator == 'function' ? comparator : undefined - return (array && array.length) ? baseUniq(array, undefined, comparator) : [] + return (array != null && array.length) ? baseUniq(array, undefined, comparator) : [] } export default uniqWith diff --git a/unzip.js b/unzip.js index 3ce2e68bb..5dc5e385d 100644 --- a/unzip.js +++ b/unzip.js @@ -26,7 +26,7 @@ const nativeMax = Math.max * // => [['a', 'b'], [1, 2], [true, false]] */ function unzip(array) { - if (!(array && array.length)) { + if (!(array != null && array.length)) { return [] } let length = 0 diff --git a/unzipWith.js b/unzipWith.js index c174859ac..b6586523f 100644 --- a/unzipWith.js +++ b/unzipWith.js @@ -21,7 +21,7 @@ import unzip from './unzip.js' * // => [3, 30, 300] */ function unzipWith(array, iteratee) { - if (!(array && array.length)) { + if (!(array != null && array.length)) { return [] } const result = unzip(array)