Skip to content

Instantly share code, notes, and snippets.

@mjgpy3
Created June 1, 2016 21:30
Show Gist options
  • Save mjgpy3/b0880bcb031f921adc0a484ff6a39794 to your computer and use it in GitHub Desktop.
Save mjgpy3/b0880bcb031f921adc0a484ff6a39794 to your computer and use it in GitHub Desktop.
Map/Filter implemented using Fold
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