mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-02 16:17:50 +00:00
Use consistent nullish check for array.
This commit is contained in:
@@ -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)
|
||||
: []
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
: []
|
||||
}
|
||||
|
||||
2
maxBy.js
2
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
|
||||
|
||||
2
minBy.js
2
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
|
||||
|
||||
2
nth.js
2
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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
: []
|
||||
}
|
||||
|
||||
@@ -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
2
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
|
||||
}
|
||||
|
||||
2
sumBy.js
2
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
|
||||
}
|
||||
|
||||
2
take.js
2
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)
|
||||
|
||||
@@ -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)
|
||||
: []
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
: []
|
||||
}
|
||||
|
||||
2
uniq.js
2
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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
2
unzip.js
2
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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user