Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The find function didn't check the first item in a array #1286

Closed
zach5078 opened this issue May 27, 2018 · 3 comments
Closed

The find function didn't check the first item in a array #1286

zach5078 opened this issue May 27, 2018 · 3 comments

Comments

@zach5078
Copy link

export function find (list, f) {

example:
console.log(find([3, 1, 1, 2], (v) => v > 2)) // undefined

correct version:

function find (list, f) {
  const { length } = list
  let index = 0
  let value
  while (index < length) {
    value = list[index++]
    if (f(value, index, list)) {
      return value
    }
  }
}
@vue-bot
Copy link

vue-bot commented May 27, 2018

Hello, your issue has been closed because it does not conform to our issue requirements. In order to ensure every issue provides the necessary information for us to investigate, we require the use of the Issue Helper when creating new issues. Thank you!

@vue-bot vue-bot closed this as completed May 27, 2018
@zach5078 zach5078 changed the title The find function didn't check the first item in a array The find function didn't check the first item in a array May 27, 2018
@zach5078 zach5078 changed the title The find function didn't check the first item in a array The find function didn't check the first item in a array May 27, 2018
ktsn added a commit that referenced this issue May 27, 2018
@jiraguha
Copy link

jiraguha commented Dec 5, 2019

@ktsn why proposition made by @zach5078 to solve your initial code was not taken into account. I think it was a good idea. list.filter(f)[0] is slower especially when the element to find in the list has a low index. But I am sure that you agree ;-)

@jiraguha
Copy link

jiraguha commented Dec 5, 2019

And you probably do not use the arr.find(callback(element[, index[, array]])[, thisArg]) because IE :-(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants