Skip to content

Instantly share code, notes, and snippets.

@busypeoples
Created August 15, 2017 11:05
Show Gist options
  • Save busypeoples/1b3ea68a5f897cdbefb10d372125b416 to your computer and use it in GitHub Desktop.
Save busypeoples/1b3ea68a5f897cdbefb10d372125b416 to your computer and use it in GitHub Desktop.
// 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