mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 03:17:49 +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']
|
* // => objects for ['barney']
|
||||||
*/
|
*/
|
||||||
function dropRightWhile(array, predicate) {
|
function dropRightWhile(array, predicate) {
|
||||||
return (array && array.length)
|
return (array != null && array.length)
|
||||||
? baseWhile(array, predicate, true, true)
|
? baseWhile(array, predicate, true, true)
|
||||||
: []
|
: []
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import baseWhile from './.internal/baseWhile.js'
|
|||||||
* // => objects for ['pebbles']
|
* // => objects for ['pebbles']
|
||||||
*/
|
*/
|
||||||
function dropWhile(array, predicate) {
|
function dropWhile(array, predicate) {
|
||||||
return (array && array.length)
|
return (array != null && array.length)
|
||||||
? baseWhile(array, predicate, true)
|
? baseWhile(array, predicate, true)
|
||||||
: []
|
: []
|
||||||
}
|
}
|
||||||
|
|||||||
2
maxBy.js
2
maxBy.js
@@ -20,7 +20,7 @@ import isSymbol from './isSymbol.js'
|
|||||||
function maxBy(array, iteratee) {
|
function maxBy(array, iteratee) {
|
||||||
let result
|
let result
|
||||||
let index = -1
|
let index = -1
|
||||||
const length = array ? array.length : 0
|
const length = array == null ? 0 : array.length
|
||||||
|
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
let computed
|
let computed
|
||||||
|
|||||||
2
minBy.js
2
minBy.js
@@ -20,7 +20,7 @@ import isSymbol from './isSymbol.js'
|
|||||||
function minBy(array, iteratee) {
|
function minBy(array, iteratee) {
|
||||||
let result
|
let result
|
||||||
let index = -1
|
let index = -1
|
||||||
const length = array ? array.length : 0
|
const length = array == null ? 0 : array.length
|
||||||
|
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
let computed
|
let computed
|
||||||
|
|||||||
2
nth.js
2
nth.js
@@ -21,7 +21,7 @@ import toInteger from './toInteger.js'
|
|||||||
* // => 'c'
|
* // => 'c'
|
||||||
*/
|
*/
|
||||||
function nth(array, n) {
|
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
|
export default nth
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import basePullAll from './.internal/basePullAll.js'
|
|||||||
* // => ['b', 'b']
|
* // => ['b', 'b']
|
||||||
*/
|
*/
|
||||||
function pullAll(array, values) {
|
function pullAll(array, values) {
|
||||||
return (array && array.length && values && values.length)
|
return (array != null && array.length && values != null && values.length)
|
||||||
? basePullAll(array, values)
|
? basePullAll(array, values)
|
||||||
: array
|
: array
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import basePullAll from './.internal/basePullAll.js'
|
|||||||
* // => [{ 'x': 2 }]
|
* // => [{ 'x': 2 }]
|
||||||
*/
|
*/
|
||||||
function pullAllBy(array, values, iteratee) {
|
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)
|
? basePullAll(array, values, iteratee)
|
||||||
: array
|
: array
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import basePullAll from './.internal/basePullAll.js'
|
|||||||
* // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
|
* // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
|
||||||
*/
|
*/
|
||||||
function pullAllWith(array, values, comparator) {
|
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)
|
? basePullAll(array, values, undefined, comparator)
|
||||||
: array
|
: array
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import basePullAt from './.internal/basePullAt.js'
|
|||||||
*/
|
*/
|
||||||
function remove(array, predicate) {
|
function remove(array, predicate) {
|
||||||
const result = []
|
const result = []
|
||||||
if (!(array && array.length)) {
|
if (!(array != null && array.length)) {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
let index = -1
|
let index = -1
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import baseSortedUniq from './.internal/baseSortedUniq.js'
|
|||||||
* // => [1, 2]
|
* // => [1, 2]
|
||||||
*/
|
*/
|
||||||
function sortedUniq(array) {
|
function sortedUniq(array) {
|
||||||
return (array && array.length)
|
return (array != null && array.length)
|
||||||
? baseSortedUniq(array)
|
? baseSortedUniq(array)
|
||||||
: []
|
: []
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import baseSortedUniq from './.internal/baseSortedUniq.js'
|
|||||||
* // => [1.1, 2.3]
|
* // => [1.1, 2.3]
|
||||||
*/
|
*/
|
||||||
function sortedUniqBy(array, iteratee) {
|
function sortedUniqBy(array, iteratee) {
|
||||||
return (array && array.length)
|
return (array != null && array.length)
|
||||||
? baseSortedUniq(array, iteratee)
|
? baseSortedUniq(array, iteratee)
|
||||||
: []
|
: []
|
||||||
}
|
}
|
||||||
|
|||||||
2
sum.js
2
sum.js
@@ -13,7 +13,7 @@ import baseSum from './.internal/baseSum.js'
|
|||||||
* // => 20
|
* // => 20
|
||||||
*/
|
*/
|
||||||
function sum(array) {
|
function sum(array) {
|
||||||
return (array && array.length)
|
return (array != null && array.length)
|
||||||
? baseSum(array, value => value)
|
? baseSum(array, value => value)
|
||||||
: 0
|
: 0
|
||||||
}
|
}
|
||||||
|
|||||||
2
sumBy.js
2
sumBy.js
@@ -18,7 +18,7 @@ import baseSum from './.internal/baseSum.js'
|
|||||||
* // => 20
|
* // => 20
|
||||||
*/
|
*/
|
||||||
function sumBy(array, iteratee) {
|
function sumBy(array, iteratee) {
|
||||||
return (array && array.length)
|
return (array != null && array.length)
|
||||||
? baseSum(array, iteratee)
|
? baseSum(array, iteratee)
|
||||||
: 0
|
: 0
|
||||||
}
|
}
|
||||||
|
|||||||
2
take.js
2
take.js
@@ -25,7 +25,7 @@ import toInteger from './toInteger.js'
|
|||||||
* // => []
|
* // => []
|
||||||
*/
|
*/
|
||||||
function take(array, n, guard) {
|
function take(array, n, guard) {
|
||||||
if (!(array && array.length)) {
|
if (!(array != null && array.length)) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
n = (guard || n === undefined) ? 1 : toInteger(n)
|
n = (guard || n === undefined) ? 1 : toInteger(n)
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import baseWhile from './.internal/baseWhile.js'
|
|||||||
* // => objects for ['fred', 'pebbles']
|
* // => objects for ['fred', 'pebbles']
|
||||||
*/
|
*/
|
||||||
function takeRightWhile(array, predicate) {
|
function takeRightWhile(array, predicate) {
|
||||||
return (array && array.length)
|
return (array != null && array.length)
|
||||||
? baseWhile(array, predicate, false, true)
|
? baseWhile(array, predicate, false, true)
|
||||||
: []
|
: []
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import baseWhile from './.internal/baseWhile.js'
|
|||||||
* // => objects for ['barney', 'fred']
|
* // => objects for ['barney', 'fred']
|
||||||
*/
|
*/
|
||||||
function takeWhile(array, predicate) {
|
function takeWhile(array, predicate) {
|
||||||
return (array && array.length)
|
return (array != null && array.length)
|
||||||
? baseWhile(array, predicate)
|
? baseWhile(array, predicate)
|
||||||
: []
|
: []
|
||||||
}
|
}
|
||||||
|
|||||||
2
uniq.js
2
uniq.js
@@ -18,7 +18,7 @@ import baseUniq from './.internal/baseUniq.js'
|
|||||||
* // => [2, 1]
|
* // => [2, 1]
|
||||||
*/
|
*/
|
||||||
function uniq(array) {
|
function uniq(array) {
|
||||||
return (array && array.length) ? baseUniq(array) : []
|
return (array != null && array.length) ? baseUniq(array) : []
|
||||||
}
|
}
|
||||||
|
|
||||||
export default uniq
|
export default uniq
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import baseUniq from './.internal/baseUniq.js'
|
|||||||
* // => [2.1, 1.2]
|
* // => [2.1, 1.2]
|
||||||
*/
|
*/
|
||||||
function uniqBy(array, iteratee) {
|
function uniqBy(array, iteratee) {
|
||||||
return (array && array.length) ? baseUniq(array, iteratee) : []
|
return (array != null && array.length) ? baseUniq(array, iteratee) : []
|
||||||
}
|
}
|
||||||
|
|
||||||
export default uniqBy
|
export default uniqBy
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import baseUniq from './.internal/baseUniq.js'
|
|||||||
*/
|
*/
|
||||||
function uniqWith(array, comparator) {
|
function uniqWith(array, comparator) {
|
||||||
comparator = typeof comparator == 'function' ? comparator : undefined
|
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
|
export default uniqWith
|
||||||
|
|||||||
2
unzip.js
2
unzip.js
@@ -26,7 +26,7 @@ const nativeMax = Math.max
|
|||||||
* // => [['a', 'b'], [1, 2], [true, false]]
|
* // => [['a', 'b'], [1, 2], [true, false]]
|
||||||
*/
|
*/
|
||||||
function unzip(array) {
|
function unzip(array) {
|
||||||
if (!(array && array.length)) {
|
if (!(array != null && array.length)) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
let length = 0
|
let length = 0
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import unzip from './unzip.js'
|
|||||||
* // => [3, 30, 300]
|
* // => [3, 30, 300]
|
||||||
*/
|
*/
|
||||||
function unzipWith(array, iteratee) {
|
function unzipWith(array, iteratee) {
|
||||||
if (!(array && array.length)) {
|
if (!(array != null && array.length)) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
const result = unzip(array)
|
const result = unzip(array)
|
||||||
|
|||||||
Reference in New Issue
Block a user