Skip to content

Instantly share code, notes, and snippets.

@anirudh-eka
Created August 5, 2018 15:50
Show Gist options
  • Select an option

  • Save anirudh-eka/ac04e7c74741f40b1dc5175e9919ddbd to your computer and use it in GitHub Desktop.

Select an option

Save anirudh-eka/ac04e7c74741f40b1dc5175e9919ddbd to your computer and use it in GitHub Desktop.
const mapAdd1Reducer = (a, x) => {
const transformed = x + 1;
return a.concat(transformed)
}
const filterGreaterThan2Reducer = (a, x) => {
if(x > 2) {
return a.concat(x)
} else {
return a;
}
}
[1, 2, 3]
.reduce(filterGreaterThan2Reducer, [])
.reduce(mapAdd1Reducer, []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment