Skip to content

Instantly share code, notes, and snippets.

@coolreader18
Last active February 4, 2018 04:19
Show Gist options
  • Save coolreader18/748e9f8203e6985b7720eb3d455e6c0b to your computer and use it in GitHub Desktop.
Save coolreader18/748e9f8203e6985b7720eb3d455e6c0b to your computer and use it in GitHub Desktop.
/**
* Like map, but it changes the original array.
* @param {Function} func The function to apply to the rest of the array. Gets passed the current element, its index, and the total array.
*/
Array.prototype.apply = function apply(func) {
for (var i = 0; i < this.length; i++) {
this[i] = func(this[i], i, this);
}
}
{
"name": "array-apply",
"version": "1.0.0",
"author": "coolreader18",
"repo": "gist:748e9f8203e6985b7720eb3d455e6c0b",
"main": "array-apply.js",
"license": "MIT"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment