Created
March 31, 2020 11:33
-
-
Save ilanl/196fa007694eac98a793fda94a1ac7e1 to your computer and use it in GitHub Desktop.
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 filter(arr, filterCallback) { | |
if (!Array.isArray(arr) || !arr.length || typeof filterCallback !== 'function') | |
{ | |
return []; | |
} else { | |
let result = []; | |
for (let i = 0, len = arr.length; i < len; i++) { | |
if (filterCallback(arr[i], i, arr)) { | |
result.push(arr[i]); | |
} | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment