Created
February 24, 2021 20:16
-
-
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.
This file contains hidden or 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
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