mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
Use more for-of
This commit is contained in:
@@ -19,14 +19,12 @@ const LARGE_ARRAY_SIZE = 200
|
|||||||
* @returns {Array} Returns the new array of filtered values.
|
* @returns {Array} Returns the new array of filtered values.
|
||||||
*/
|
*/
|
||||||
function baseDifference(array, values, iteratee, comparator) {
|
function baseDifference(array, values, iteratee, comparator) {
|
||||||
let index = -1
|
|
||||||
let includes = arrayIncludes
|
let includes = arrayIncludes
|
||||||
let isCommon = true
|
let isCommon = true
|
||||||
const { length } = array
|
|
||||||
const result = []
|
const result = []
|
||||||
const valuesLength = values.length
|
const valuesLength = values.length
|
||||||
|
|
||||||
if (!length) {
|
if (!array.length) {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
if (iteratee) {
|
if (iteratee) {
|
||||||
@@ -42,8 +40,7 @@ function baseDifference(array, values, iteratee, comparator) {
|
|||||||
values = new SetCache(values)
|
values = new SetCache(values)
|
||||||
}
|
}
|
||||||
outer:
|
outer:
|
||||||
while (++index < length) {
|
for (let value of array) {
|
||||||
let value = array[index]
|
|
||||||
const computed = iteratee == null ? value : iteratee(value)
|
const computed = iteratee == null ? value : iteratee(value)
|
||||||
|
|
||||||
value = (comparator || value !== 0) ? value : 0
|
value = (comparator || value !== 0) ? value : 0
|
||||||
|
|||||||
@@ -8,11 +8,9 @@
|
|||||||
*/
|
*/
|
||||||
function baseSum(array, iteratee) {
|
function baseSum(array, iteratee) {
|
||||||
let result
|
let result
|
||||||
let index = -1
|
|
||||||
const { length } = array
|
|
||||||
|
|
||||||
while (++index < length) {
|
for (value of array) {
|
||||||
const current = iteratee(array[index])
|
const current = iteratee(value)
|
||||||
if (current !== undefined) {
|
if (current !== undefined) {
|
||||||
result = result === undefined ? current : (result + current)
|
result = result === undefined ? current : (result + current)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,12 +15,7 @@ function copyObject(source, props, object, customizer) {
|
|||||||
const isNew = !object
|
const isNew = !object
|
||||||
object || (object = {})
|
object || (object = {})
|
||||||
|
|
||||||
let index = -1
|
for (const key of props) {
|
||||||
const length = props.length
|
|
||||||
|
|
||||||
while (++index < length) {
|
|
||||||
const key = props[index]
|
|
||||||
|
|
||||||
let newValue = customizer
|
let newValue = customizer
|
||||||
? customizer(object[key], source[key], key, object, source)
|
? customizer(object[key], source[key], key, object, source)
|
||||||
: undefined
|
: undefined
|
||||||
|
|||||||
4
cond.js
4
cond.js
@@ -38,9 +38,7 @@ function cond(pairs) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
return (...args) => {
|
return (...args) => {
|
||||||
let index = -1
|
for (const pair of pairs) {
|
||||||
while (++index < length) {
|
|
||||||
const pair = pairs[index]
|
|
||||||
if (pair[0].apply(this, args)) {
|
if (pair[0].apply(this, args)) {
|
||||||
return pair[1].apply(this, args)
|
return pair[1].apply(this, args)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,12 +12,11 @@
|
|||||||
* // => { 'a': 1, 'b': 2 }
|
* // => { 'a': 1, 'b': 2 }
|
||||||
*/
|
*/
|
||||||
function fromPairs(pairs) {
|
function fromPairs(pairs) {
|
||||||
let index = -1
|
|
||||||
const length = pairs == null ? 0 : pairs.length
|
|
||||||
const result = {}
|
const result = {}
|
||||||
|
if (pairs == null) {
|
||||||
while (++index < length) {
|
return result
|
||||||
const pair = pairs[index]
|
}
|
||||||
|
for (const pair of pairs) {
|
||||||
result[pair[0]] = pair[1]
|
result[pair[0]] = pair[1]
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
|||||||
9
maxBy.js
9
maxBy.js
@@ -19,12 +19,11 @@ import isSymbol from './isSymbol.js'
|
|||||||
*/
|
*/
|
||||||
function maxBy(array, iteratee) {
|
function maxBy(array, iteratee) {
|
||||||
let result
|
let result
|
||||||
let index = -1
|
if (array == null) {
|
||||||
const length = array == null ? 0 : array.length
|
return result
|
||||||
|
}
|
||||||
while (++index < length) {
|
for (const value of array) {
|
||||||
let computed
|
let computed
|
||||||
const value = array[index]
|
|
||||||
const current = iteratee(value)
|
const current = iteratee(value)
|
||||||
|
|
||||||
if (current != null && (computed === undefined
|
if (current != null && (computed === undefined
|
||||||
|
|||||||
9
minBy.js
9
minBy.js
@@ -19,12 +19,11 @@ import isSymbol from './isSymbol.js'
|
|||||||
*/
|
*/
|
||||||
function minBy(array, iteratee) {
|
function minBy(array, iteratee) {
|
||||||
let result
|
let result
|
||||||
let index = -1
|
if (array == null) {
|
||||||
const length = array == null ? 0 : array.length
|
return result
|
||||||
|
}
|
||||||
while (++index < length) {
|
for (const value of array) {
|
||||||
let computed
|
let computed
|
||||||
const value = array[index]
|
|
||||||
const current = iteratee(value)
|
const current = iteratee(value)
|
||||||
|
|
||||||
if (current != null && (computed === undefined
|
if (current != null && (computed === undefined
|
||||||
|
|||||||
Reference in New Issue
Block a user