Created
May 3, 2017 17:18
-
-
Save devan-sisson/569706cee6db33c05a8e163795671876 to your computer and use it in GitHub Desktop.
This file contains 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
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