Skip to content

Wrong return value (CH3, Array methods, Finding elements) #11

Description

@BAHER1088

There's a mistake in CH3 > Array methods > Finding elements

The mistake is in saying that the function “returns the element” when the condition is met. In this code, the callback function does not return the element itself. It returns the result of the comparison e === 6 or e === 10, which is a boolean value (true or false). The function’s job is only to tell find() whether the current element matches the condition.

The correct explanation is that the callback function returns true when the element satisfies the condition, and false otherwise. When find() receives true from the callback, it stops iterating and returns the corresponding element from the array. If the callback never returns true, then find() returns undefined.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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