Skip to content

Commit 3e2b0bb

Browse files
committed
Use more for-of
1 parent f3957ac commit 3e2b0bb

File tree

7 files changed

+18
-33
lines changed

7 files changed

+18
-33
lines changed

.internal/baseDifference.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@ const LARGE_ARRAY_SIZE = 200
1919
* @returns {Array} Returns the new array of filtered values.
2020
*/
2121
function baseDifference(array, values, iteratee, comparator) {
22-
let index = -1
2322
let includes = arrayIncludes
2423
let isCommon = true
25-
const { length } = array
2624
const result = []
2725
const valuesLength = values.length
2826

29-
if (!length) {
27+
if (!array.length) {
3028
return result
3129
}
3230
if (iteratee) {
@@ -42,8 +40,7 @@ function baseDifference(array, values, iteratee, comparator) {
4240
values = new SetCache(values)
4341
}
4442
outer:
45-
while (++index < length) {
46-
let value = array[index]
43+
for (let value of array) {
4744
const computed = iteratee == null ? value : iteratee(value)
4845

4946
value = (comparator || value !== 0) ? value : 0

.internal/baseSum.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
*/
99
function baseSum(array, iteratee) {
1010
let result
11-
let index = -1
12-
const { length } = array
1311

14-
while (++index < length) {
15-
const current = iteratee(array[index])
12+
for (value of array) {
13+
const current = iteratee(value)
1614
if (current !== undefined) {
1715
result = result === undefined ? current : (result + current)
1816
}

.internal/copyObject.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@ function copyObject(source, props, object, customizer) {
1515
const isNew = !object
1616
object || (object = {})
1717

18-
let index = -1
19-
const length = props.length
20-
21-
while (++index < length) {
22-
const key = props[index]
23-
18+
for (const key of props) {
2419
let newValue = customizer
2520
? customizer(object[key], source[key], key, object, source)
2621
: undefined

cond.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ function cond(pairs) {
3838
})
3939

4040
return (...args) => {
41-
let index = -1
42-
while (++index < length) {
43-
const pair = pairs[index]
41+
for (const pair of pairs) {
4442
if (pair[0].apply(this, args)) {
4543
return pair[1].apply(this, args)
4644
}

fromPairs.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@
1212
* // => { 'a': 1, 'b': 2 }
1313
*/
1414
function fromPairs(pairs) {
15-
let index = -1
16-
const length = pairs == null ? 0 : pairs.length
1715
const result = {}
18-
19-
while (++index < length) {
20-
const pair = pairs[index]
16+
if (pairs == null) {
17+
return result
18+
}
19+
for (const pair of pairs) {
2120
result[pair[0]] = pair[1]
2221
}
2322
return result

maxBy.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ import isSymbol from './isSymbol.js'
1919
*/
2020
function maxBy(array, iteratee) {
2121
let result
22-
let index = -1
23-
const length = array == null ? 0 : array.length
24-
25-
while (++index < length) {
22+
if (array == null) {
23+
return result
24+
}
25+
for (const value of array) {
2626
let computed
27-
const value = array[index]
2827
const current = iteratee(value)
2928

3029
if (current != null && (computed === undefined

minBy.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ import isSymbol from './isSymbol.js'
1919
*/
2020
function minBy(array, iteratee) {
2121
let result
22-
let index = -1
23-
const length = array == null ? 0 : array.length
24-
25-
while (++index < length) {
22+
if (array == null) {
23+
return result
24+
}
25+
for (const value of array) {
2626
let computed
27-
const value = array[index]
2827
const current = iteratee(value)
2928

3029
if (current != null && (computed === undefined

0 commit comments

Comments
 (0)