Przeglądaj źródła

Update util find (#1205)

perf: update util find
Bichi Kim 7 lat temu
rodzic
commit
e556943cec
1 zmienionych plików z 9 dodań i 1 usunięć
  1. 9 1
      src/util.js

+ 9 - 1
src/util.js

@@ -7,7 +7,15 @@
  * @return {*}
  * @return {*}
  */
  */
 export function find (list, f) {
 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
+    }
+  }
 }
 }
 
 
 /**
 /**