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

Open Beginner friendly
#11 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
65/100
Issue type
Documentation
Clarity
Clearly specified
Activity status
Stale
Tech stack
javascript
Domain
documentation

Research direction

Find the CH3 > Array methods > Finding elements passage described in the issue and review its explanation of the callback and find(). Correct the wording so it distinguishes the callback's boolean result from the element returned by find(), including the undefined case when no match is found.

Written by the indexing model from the issue text.

Description

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.

Dominant language
HTML
Stars
370
Forks
218
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PacktPublishing/JavaScript-from-Beginner-to-Professional

All issues in PacktPublishing/JavaScript-from-Beginner-to-Professional

Similar issues

More Documentation issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.