Created
October 26, 2023 05:13
-
-
Save mokshchadha/fe7f3a415f49dace6e8830a0dd202001 to your computer and use it in GitHub Desktop.
create map filter from scratch
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
function mapArray(arr,cb){ | |
let res = []; | |
for(const e of arr){ | |
res.push(cb(e)); | |
} | |
return res; | |
} | |
function filterArray(arr, cb){ | |
let res = []; | |
for(const e of arr){ | |
const isAllowed = cb(e); | |
if(isAllowed){ | |
res.push(e) | |
} | |
} | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment