-
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
c27c0df
commit 97c9280
Showing
2 changed files
with
34 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,17 @@ | ||
// Do NOT use .filter, to complete this function. | ||
// Similar to `find` but you will return an array of all elements that passed the truth test | ||
// Return an empty array if no elements pass the truth test | ||
|
||
function filter(elements, cb) { | ||
|
||
let targetElementsArr=[]; | ||
|
||
for(let index=0;index<elements.length;index++){ | ||
if(cb(elements[index])){ | ||
targetElementsArr.push(elements[index]); | ||
} | ||
} | ||
return targetElementsArr; | ||
} | ||
|
||
module.exports=filter; |
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,17 @@ | ||
|
||
let filterFunc=require('../filter'); | ||
|
||
const items = [1, 2, 3, 4, 5, 5]; | ||
|
||
function isEvenNumber(element){ | ||
if(element%2==0){ | ||
return true; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
|
||
let evenNumbers=filterFunc(items,isEvenNumber); | ||
|
||
console.log("Even Numbers :",evenNumbers); |