Skip to content

Commit 6246ac2

Browse files
Misleading comments
comments in example codes are slightly misleading
1 parent 3a6d70b commit 6246ac2

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

1-js/05-data-types/05-array-methods/article.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ Here the [arr.find](mdn:js/Array/find) method comes in handy.
275275
The syntax is:
276276
```js
277277
let result = arr.find(function(item, index, array) {
278-
// should return true if the item is what we are looking for
278+
// if true is returned, item is returned and iteration is stopped
279+
// for falsy scenario returns undefined
279280
});
280281
```
281282

@@ -313,11 +314,12 @@ The `find` method looks for a single (first) element that makes the function ret
313314

314315
If there may be many, we can use [arr.filter(fn)](mdn:js/Array/filter).
315316

316-
The syntax is roughly the same as `find`, but it returns an array of matching elements:
317+
The syntax is similar to `find`, but filter continues to iterate for all array elements even if `true` is already returned:
317318

318319
```js
319320
let results = arr.filter(function(item, index, array) {
320-
// should return true if the item passes the filter
321+
// if true item is pushed to results and iteration continues
322+
// returns empty array for complete falsy scenario
321323
});
322324
```
323325

0 commit comments

Comments
 (0)