diff --git a/guide/english/certifications/javascript-algorithms-and-data-structures/basic-algorithm-scripting/finders-keepers/index.md b/guide/english/certifications/javascript-algorithms-and-data-structures/basic-algorithm-scripting/finders-keepers/index.md index 02c6b45725..596b8ff092 100644 --- a/guide/english/certifications/javascript-algorithms-and-data-structures/basic-algorithm-scripting/finders-keepers/index.md +++ b/guide/english/certifications/javascript-algorithms-and-data-structures/basic-algorithm-scripting/finders-keepers/index.md @@ -39,3 +39,19 @@ function findElement(arr, func) { * The `num` variable is being passed into the function, so we set it to each index in our array. * The pre-defined function already checks each number for us, so if it is "true", we return that num. * If none of the numbers in the array pass the function's test, we return undefined. + + +## Advanced Solution + +```javascript +function findElement(arr, func) { + return arr[(arr.map(func)).indexOf(true)]; +} +``` + +## Code Explanation + +1. Look through the array given in the 1st paramater "arr" using the .map() method +2. Use the function in the 2nd parameter as the callback function in arr.map() +3. Acquire the index of the first number that meets the condition in the function. +4. Use that index to display the first available number that meets the condition.