Skip to content

Instantly share code, notes, and snippets.

@wattry
Created February 24, 2021 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wattry/61f388723d649bc5a5d5895700d27594 to your computer and use it in GitHub Desktop.
Save wattry/61f388723d649bc5a5d5895700d27594 to your computer and use it in GitHub Desktop.
A function to filter an array and map the result in one call.
Array.prototype.arrayMap = function(callback) {
const newData = [];
for (let i = 0; i < this.length; i++) {
const entry = callback(this[i]);
if (entry !== null && entry !== undefined) {
newData.push(entry);
}
}
return newData;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment