mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 10:07:48 +00:00
Use more destructuring.
This commit is contained in:
@@ -9,7 +9,7 @@ import eq from '../eq.js'
|
|||||||
* @returns {number} Returns the index of the matched value, else `-1`.
|
* @returns {number} Returns the index of the matched value, else `-1`.
|
||||||
*/
|
*/
|
||||||
function assocIndexOf(array, key) {
|
function assocIndexOf(array, key) {
|
||||||
let length = array.length
|
let { length } = array
|
||||||
while (length--) {
|
while (length--) {
|
||||||
if (eq(array[length][0], key)) {
|
if (eq(array[length][0], key)) {
|
||||||
return length
|
return length
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ function initCloneByTag(object, tag, cloneFunc, isDeep) {
|
|||||||
* @returns {Array} Returns the initialized clone.
|
* @returns {Array} Returns the initialized clone.
|
||||||
*/
|
*/
|
||||||
function initCloneArray(array) {
|
function initCloneArray(array) {
|
||||||
const length = array.length
|
const { length } = array
|
||||||
const result = new array.constructor(length)
|
const result = new array.constructor(length)
|
||||||
|
|
||||||
// Add properties assigned by `RegExp#exec`.
|
// Add properties assigned by `RegExp#exec`.
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ function baseDifference(array, values, iteratee, comparator) {
|
|||||||
let index = -1
|
let index = -1
|
||||||
let includes = arrayIncludes
|
let includes = arrayIncludes
|
||||||
let isCommon = true
|
let isCommon = true
|
||||||
const length = array.length
|
const { length } = array
|
||||||
const result = []
|
const result = []
|
||||||
const valuesLength = values.length
|
const valuesLength = values.length
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
* @returns {number} Returns the index of the matched value, else `-1`.
|
* @returns {number} Returns the index of the matched value, else `-1`.
|
||||||
*/
|
*/
|
||||||
function baseFindIndex(array, predicate, fromIndex, fromRight) {
|
function baseFindIndex(array, predicate, fromIndex, fromRight) {
|
||||||
const length = array.length
|
const { length } = array
|
||||||
let index = fromIndex + (fromRight ? 1 : -1)
|
let index = fromIndex + (fromRight ? 1 : -1)
|
||||||
|
|
||||||
while ((fromRight ? index-- : ++index < length)) {
|
while ((fromRight ? index-- : ++index < length)) {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import isFlattenable from './isFlattenable.js'
|
|||||||
*/
|
*/
|
||||||
function baseFlatten(array, depth, predicate, isStrict, result) {
|
function baseFlatten(array, depth, predicate, isStrict, result) {
|
||||||
let index = -1
|
let index = -1
|
||||||
const length = array.length
|
const { length } = array
|
||||||
|
|
||||||
predicate || (predicate = isFlattenable)
|
predicate || (predicate = isFlattenable)
|
||||||
result || (result = [])
|
result || (result = [])
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
*/
|
*/
|
||||||
function baseIndexOfWith(array, value, fromIndex, comparator) {
|
function baseIndexOfWith(array, value, fromIndex, comparator) {
|
||||||
let index = fromIndex - 1
|
let index = fromIndex - 1
|
||||||
const length = array.length
|
const { length } = array
|
||||||
|
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
if (comparator(array[index], value)) {
|
if (comparator(array[index], value)) {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import isIndex from './isIndex.js'
|
|||||||
* @returns {*} Returns the nth element of `array`.
|
* @returns {*} Returns the nth element of `array`.
|
||||||
*/
|
*/
|
||||||
function baseNth(array, n) {
|
function baseNth(array, n) {
|
||||||
const length = array.length
|
const { length } = array
|
||||||
if (!length) {
|
if (!length) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
function baseSlice(array, start, end) {
|
function baseSlice(array, start, end) {
|
||||||
let index = -1
|
let index = -1
|
||||||
let length = array.length
|
let { length } = array
|
||||||
|
|
||||||
if (start < 0) {
|
if (start < 0) {
|
||||||
start = -start > length ? 0 : (length + start)
|
start = -start > length ? 0 : (length + start)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
* @returns {Array} Returns `array`.
|
* @returns {Array} Returns `array`.
|
||||||
*/
|
*/
|
||||||
function baseSortBy(array, comparer) {
|
function baseSortBy(array, comparer) {
|
||||||
let length = array.length
|
let { length } = array
|
||||||
|
|
||||||
array.sort(comparer)
|
array.sort(comparer)
|
||||||
while (length--) {
|
while (length--) {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ function baseSortedUniq(array, iteratee) {
|
|||||||
let index = -1
|
let index = -1
|
||||||
let resIndex = 0
|
let resIndex = 0
|
||||||
|
|
||||||
const length = array.length
|
const { length } = array
|
||||||
const result = []
|
const result = []
|
||||||
|
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
function baseSum(array, iteratee) {
|
function baseSum(array, iteratee) {
|
||||||
let result
|
let result
|
||||||
let index = -1
|
let index = -1
|
||||||
const length = array.length
|
const { length } = array
|
||||||
|
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
const current = iteratee(array[index])
|
const current = iteratee(array[index])
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ function baseUniq(array, iteratee, comparator) {
|
|||||||
let includes = arrayIncludes
|
let includes = arrayIncludes
|
||||||
let isCommon = true
|
let isCommon = true
|
||||||
|
|
||||||
const length = array.length
|
const { length } = array
|
||||||
const result = []
|
const result = []
|
||||||
let seen = result
|
let seen = result
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import baseSlice from './baseSlice.js'
|
|||||||
* @returns {Array} Returns the slice of `array`.
|
* @returns {Array} Returns the slice of `array`.
|
||||||
*/
|
*/
|
||||||
function baseWhile(array, predicate, isDrop, fromRight) {
|
function baseWhile(array, predicate, isDrop, fromRight) {
|
||||||
const length = array.length
|
const { length } = array
|
||||||
let index = fromRight ? length : -1
|
let index = fromRight ? length : -1
|
||||||
|
|
||||||
while ((fromRight ? index-- : ++index < length) &&
|
while ((fromRight ? index-- : ++index < length) &&
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import baseSlice from './baseSlice.js'
|
|||||||
* @returns {Array} Returns the cast slice.
|
* @returns {Array} Returns the cast slice.
|
||||||
*/
|
*/
|
||||||
function castSlice(array, start, end) {
|
function castSlice(array, start, end) {
|
||||||
const length = array.length
|
const { length } = array
|
||||||
end = end === undefined ? length : end
|
end = end === undefined ? length : end
|
||||||
return (!start && end >= length) ? array : baseSlice(array, start, end)
|
return (!start && end >= length) ? array : baseSlice(array, start, end)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ const PLACEHOLDER = '__lodash_placeholder__'
|
|||||||
*/
|
*/
|
||||||
function replaceHolders(array, placeholder) {
|
function replaceHolders(array, placeholder) {
|
||||||
let index = -1
|
let index = -1
|
||||||
const length = array.length
|
const { length } = array
|
||||||
let resIndex = 0
|
let resIndex = 0
|
||||||
const result = []
|
const result = []
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
*/
|
*/
|
||||||
function strictIndexOf(array, value, fromIndex) {
|
function strictIndexOf(array, value, fromIndex) {
|
||||||
let index = fromIndex - 1
|
let index = fromIndex - 1
|
||||||
const length = array.length
|
const { length } = array
|
||||||
|
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
if (array[index] === value) {
|
if (array[index] === value) {
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ function remove(array, predicate) {
|
|||||||
}
|
}
|
||||||
let index = -1
|
let index = -1
|
||||||
const indexes = []
|
const indexes = []
|
||||||
const length = array.length
|
const { length } = array
|
||||||
|
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
const value = array[index]
|
const value = array[index]
|
||||||
|
|||||||
Reference in New Issue
Block a user