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