Browse Source

Update util find (#1205)

perf: update util find
Bichi Kim 7 năm trước cách đây
mục cha
commit
e556943cec
1 tập tin đã thay đổi với 9 bổ sung1 xóa
  1. 9 1
      src/util.js

+ 9 - 1
src/util.js

@@ -7,7 +7,15 @@
  * @return {*}
  */
 export function find (list, f) {
-  return list.filter(f)[0]
+  const { length } = list
+  let index = 0
+  let value
+  while (++index < length) {
+    value = list[index]
+    if (f(value, index, list)) {
+      return value
+    }
+  }
 }
 
 /**