-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b4c4eaf
commit c27c0df
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Do NOT use .includes, to complete this function. | ||
// Look through each value in `elements` and pass each element to `cb`. | ||
// If `cb` returns `true` then return that element. | ||
// Return `undefined` if no elements pass the truth test. | ||
|
||
|
||
function find(elements, cb) { | ||
|
||
let targetElement; | ||
|
||
for(let index=0;index<elements.length;index++){ | ||
|
||
if(cb(elements[index])){ | ||
targetElement=elements[index]; | ||
return targetElement; | ||
} | ||
} | ||
|
||
return targetElement; | ||
|
||
} | ||
|
||
module.exports=find; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const findFunc=require('../find'); | ||
|
||
const items = [1, 2, 3, 4, 5, 5]; | ||
|
||
function isEvenNumber(element){ | ||
if(element%2==0){ | ||
return true; | ||
} | ||
} | ||
|
||
const evenNumber=findFunc(items,isEvenNumber); | ||
|
||
console.log("Even Number :",evenNumber); |