Add a solution for Finders Keepers challenge (#35655)
* Add a solution for Finders Keepers challenge * Update link to markdown * fix: removed repl.it link * fix: made this the Intermediate Solution * fix: added correct Intermediate icon
This commit is contained in:
		
				
					committed by
					
						
						Randell Dawson
					
				
			
			
				
	
			
			
			
						parent
						
							4a7861ce87
						
					
				
				
					commit
					4bc1d74f2a
				
			@@ -1,7 +1,13 @@
 | 
				
			|||||||
---
 | 
					---
 | 
				
			||||||
title: Finders Keepers
 | 
					title: Finders Keepers
 | 
				
			||||||
---
 | 
					---
 | 
				
			||||||
## Problem Explanation
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 Remember to use <a>**`Read-Search-Ask`**</a> if you get stuck. Try to pair program  and write your own code 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					##  Problem Explanation:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
We need to return the element from an array that passes a function. Both the `function` and the `array` are passed into our function `findElement(arr, func)`.
 | 
					We need to return the element from an array that passes a function. Both the `function` and the `array` are passed into our function `findElement(arr, func)`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Hint: 1
 | 
					## Hint: 1
 | 
				
			||||||
@@ -16,7 +22,7 @@ Looking through the array can be done with a `for` loop.
 | 
				
			|||||||
Do not forget, if none of the numbers in the array pass the test, it should return `undefined`.
 | 
					Do not forget, if none of the numbers in the array pass the test, it should return `undefined`.
 | 
				
			||||||
>*try to solve the problem now*
 | 
					>*try to solve the problem now*
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Basic Solution
 | 
					##  Basic Code Solution:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```javascript
 | 
					```javascript
 | 
				
			||||||
function findElement(arr, func) {
 | 
					function findElement(arr, func) {
 | 
				
			||||||
@@ -40,8 +46,18 @@ function findElement(arr, func) {
 | 
				
			|||||||
* The pre-defined function already checks each number for us, so if it is "true", we return that num.
 | 
					* 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.
 | 
					* If none of the numbers in the array pass the function's test, we return undefined.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					##   Intermediate Code Solution:
 | 
				
			||||||
 | 
					```javascript
 | 
				
			||||||
 | 
					function findElement(arr, func) {
 | 
				
			||||||
 | 
					  return arr.find(func);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Advanced Solution
 | 
					#### Relevant Links
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					*   [Array.prototype.find](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					##  Advanced Code Solution:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```javascript
 | 
					```javascript
 | 
				
			||||||
function findElement(arr, func) {
 | 
					function findElement(arr, func) {
 | 
				
			||||||
@@ -55,3 +71,9 @@ function findElement(arr, func) {
 | 
				
			|||||||
2. Use the function in the 2nd parameter as the callback function in arr.map()
 | 
					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.
 | 
					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.
 | 
					4. Use that index to display the first available number that meets the condition.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					##  NOTES FOR CONTRIBUTIONS:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					*    **DO NOT** add solutions that are similar to any existing solutions. If you think it is **_similar but better_**, then try to merge (or replace) the existing similar solution.
 | 
				
			||||||
 | 
					*   Add an explanation of your solution.
 | 
				
			||||||
 | 
					*   Categorize the solution in one of the following categories -- **Basic**, **Intermediate** and **Advanced**. 
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user