Skip to content

Commit

Permalink
Update util find (#1205)
Browse files Browse the repository at this point in the history
perf: update util find
  • Loading branch information
bichikim authored and ktsn committed Mar 29, 2018
1 parent f5ff95e commit e556943
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

/**
Expand Down

1 comment on commit e556943

@Vcxinuo
Copy link

@Vcxinuo Vcxinuo commented on e556943 May 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
    
  • }
  • }

Please sign in to comment.