Skip to content

Instantly share code, notes, and snippets.

@ilanl
Created March 31, 2020 11:33
Show Gist options
  • Save ilanl/196fa007694eac98a793fda94a1ac7e1 to your computer and use it in GitHub Desktop.
Save ilanl/196fa007694eac98a793fda94a1ac7e1 to your computer and use it in GitHub Desktop.
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