Use consistent nullish check for array.

This commit is contained in:
John-David Dalton
2017-02-28 13:39:50 -08:00
parent 46ffbc1d90
commit d0f23b67ac
21 changed files with 21 additions and 21 deletions

View File

@@ -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)
: []
}

View File

@@ -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)
: []
}

View File

@@ -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

View File

@@ -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

2
nth.js
View File

@@ -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

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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

View File

@@ -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)
: []
}

View File

@@ -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)
: []
}

2
sum.js
View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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)

View File

@@ -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)
: []
}

View File

@@ -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)
: []
}

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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)