Skip to content

Instantly share code, notes, and snippets.

@crutchcorn
Last active March 3, 2020 03:30
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 crutchcorn/823bab26ad9c7fe1e166c02f58afa3cb to your computer and use it in GitHub Desktop.
Save crutchcorn/823bab26ad9c7fe1e166c02f58afa3cb to your computer and use it in GitHub Desktop.
Array.prototype.filter = function (callback) {
const arr = this;
const returnedVal = [];
for (const i = 0; i < arr.length; i++) {
const exist = callback(arr[i], i, arr);
if (exist) {
returnedVal.push(arr[i]);
}
}
return returnedVal;
};
Array.prototype.map = function (callback) {
const arr = this;
const returnedVal = [];
for (const i = 0; i < arr.length; i++) {
const exist = callback(arr[i], i, arr);
returnedVal.push(exist);
}
return returnedVal;
}
Array.prototype.forEach = function (callback) {
const arr = this;
for (const i = 0; i < arr.length; i++) {
callback(arr[i], i, arr);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment