From 271b2c34342618485d674fa9cb041e145ddc6586 Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Thu, 22 Nov 2018 22:14:40 +0100 Subject: [PATCH] Add new solution version that directly returns (#34427) In this case (that is quite typical) more complicated language features are not necessary. --- .../index.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/guide/english/certifications/javascript-algorithms-and-data-structures/basic-data-structures/check-for-the-presence-of-an-element-with-indexof/index.md b/guide/english/certifications/javascript-algorithms-and-data-structures/basic-data-structures/check-for-the-presence-of-an-element-with-indexof/index.md index f99df8bed2..c10afafa50 100644 --- a/guide/english/certifications/javascript-algorithms-and-data-structures/basic-data-structures/check-for-the-presence-of-an-element-with-indexof/index.md +++ b/guide/english/certifications/javascript-algorithms-and-data-structures/basic-data-structures/check-for-the-presence-of-an-element-with-indexof/index.md @@ -26,3 +26,12 @@ return arr.indexOf(elem) >= 0 ? true : false; } console.log(quickCheck(['squash', 'onions', 'shallots'], 'mushrooms')); ``` +- `Solution-3` demonstrates how the problem can be solved by directly returning result of the comparison. + +## Solution-3: +```javascript +function quickCheck(arr, elem) { + return arr.indexOf(elem) != -1; +} +console.log(quickCheck(['squash', 'onions', 'shallots'], 'mushrooms')); +```