Skip to content

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

@ghost

Description

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions