Last active
August 29, 2015 14:02
-
-
Save jremmen/5928ddb7412b676021a4 to your computer and use it in GitHub Desktop.
js: multimap and multireduce array methods
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
Array.prototype.multimap = function(f) { | |
return this.length == 0 ? [] : [(this[0] instanceof Array ? this[0].multimap(f) : f(this[0]))].concat(this.slice(1).multimap(f)); | |
} | |
Array.prototype.multireduce = function(f, z) { | |
return this.length == 0 ? z : f((this[0] instanceof Array ? this[0].multireduce(f, z) : this[0]), this.slice(1).multireduce(f, z)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment