Created
August 15, 2017 11:05
-
-
Save busypeoples/1b3ea68a5f897cdbefb10d372125b416 to your computer and use it in GitHub Desktop.
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
// Why the Hipsters Reduce Everything! | |
// Map implementation | |
import R from 'ramda' | |
const map = (f, data) => | |
R.reduce((xs, x) => { | |
return [...xs, f(x)] | |
}, [], data) | |
// Filter implementation | |
const filter = (f, data) => | |
R.reduce((xs, x) => { | |
return f(x) ? [...xs, x] : xs | |
}, [], data) | |
const data = [1, 2, 3, 4, 5] | |
console.log(map(x => x + 10, data)) | |
console.log(filter(x => x > 3, data)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment