From 6246ac2fc627ff6f587d4220a301dc58c8b33ea3 Mon Sep 17 00:00:00 2001 From: Varun Date: Wed, 6 Feb 2019 15:35:54 +0530 Subject: [PATCH] Misleading comments comments in example codes are slightly misleading --- 1-js/05-data-types/05-array-methods/article.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/1-js/05-data-types/05-array-methods/article.md b/1-js/05-data-types/05-array-methods/article.md index 08c58759..42bbd946 100644 --- a/1-js/05-data-types/05-array-methods/article.md +++ b/1-js/05-data-types/05-array-methods/article.md @@ -275,7 +275,8 @@ Here the [arr.find](mdn:js/Array/find) method comes in handy. The syntax is: ```js let result = arr.find(function(item, index, array) { - // should return true if the item is what we are looking for + // if true is returned, item is returned and iteration is stopped + // for falsy scenario returns undefined }); ``` @@ -313,11 +314,12 @@ The `find` method looks for a single (first) element that makes the function ret If there may be many, we can use [arr.filter(fn)](mdn:js/Array/filter). -The syntax is roughly the same as `find`, but it returns an array of matching elements: +The syntax is similar to `find`, but filter continues to iterate for all array elements even if `true` is already returned: ```js let results = arr.filter(function(item, index, array) { - // should return true if the item passes the filter + // if true item is pushed to results and iteration continues + // returns empty array for complete falsy scenario }); ```