Skip to content

Commit 832e91e

Browse files
committed
fix: improve findFirstValueAndIndex function
1 parent 66cdc32 commit 832e91e

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/utils/optimizeCallback.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import typed from 'typed-function'
2-
import { get, arraySize } from './array.js'
2+
import { findFirst } from './array.js'
33
import { typeOf as _typeOf } from './is.js'
44

55
/**
@@ -42,13 +42,16 @@ export function optimizeCallback (callback, array, name, options) {
4242
}
4343

4444
function findFirstValueAndIndex (array) {
45-
if((array.isMatrix && array.valueOf().length === 0) || (Array.isArray(array) && array.length === 0)) {
46-
return [undefined, []]
45+
if (array.isMatrix) {
46+
if (array.valueOf().length === 0) return [undefined, []]
47+
const firstIndex = array.size().map(() => 0)
48+
const firstValue = array.get(firstIndex)
49+
return [firstValue, firstIndex]
50+
} else {
51+
if (array.length === 0) return [undefined, []]
52+
const { value, index } = findFirst(array)
53+
return [value, index]
4754
}
48-
const firstIndex = (array.isMatrix ? array.size() : arraySize(array)).map(() => 0)
49-
const firstValue = array.isMatrix ? array.get(firstIndex) : get(array, firstIndex)
50-
51-
return [firstValue, firstIndex]
5255
}
5356

5457
export function findNumberOfArguments (callback, array) {

0 commit comments

Comments
 (0)