Skip to content

Instantly share code, notes, and snippets.

@devan-sisson
Created May 3, 2017 17:18
Show Gist options
  • Save devan-sisson/569706cee6db33c05a8e163795671876 to your computer and use it in GitHub Desktop.
Save devan-sisson/569706cee6db33c05a8e163795671876 to your computer and use it in GitHub Desktop.
class AltArray extends Array {
constructor(...args) {
super(...args);
}
altMap(fn) {
var newArr = []
for (let i = 0; i < this.length; i++) {
newArr.push(fn(this[i], i, this));
}
return newArr;
}
altForEach(fn) {
for (let i = 0; i < this.length; i++) {
fn(this[i], i, this);
}
}
altReduce(fn, initialValue) {
var i = arguments.length > 1 ? 0 : 1;
var acc = arguments.length > 1 ? initialValue : this[1];
for (i; i < this.length; i++) {
acc = fn(acc, this[i], i, this)
}
return acc;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment