Created
June 1, 2016 21:30
-
-
Save mjgpy3/b0880bcb031f921adc0a484ff6a39794 to your computer and use it in GitHub Desktop.
Map/Filter implemented using Fold
This file contains hidden or 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
var filter = function (xs, p) { | |
return xs.reduce(function (results, v) { | |
return results.concat(p(v) ? [v] : []); | |
}, []); | |
}; | |
var map = function (xs, f) { | |
return xs.reduce(function (results, v) { | |
return results.concat([f(v)]); | |
}, []); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment