1 | const {curry} = require('../fp');
|
2 |
|
3 | Object.prototype.map = function(fn){ return Object.entries(this).reduce((acc,[k,v]) => ({...acc,[k]:fn(v,k)}),{}); };
|
4 | Object.prototype.filter = function(fn){ return Object.entries(this).reduce((acc,[k,v]) => fn(v,k) && ({...acc,[k]:v}),{}) || {}; };
|
5 |
|
6 | const map = curry((fn, col) => col.map(fn));
|
7 | const filter = curry((fn, col) => col.filter(fn));
|
8 |
|
9 | module.exports = {map, filter};
|