Skip to content

Instantly share code, notes, and snippets.

@jooyunghan
Last active January 9, 2018 06:54
Show Gist options
  • Save jooyunghan/c540902cca7cd733cfa2c6f2f27ccf2f to your computer and use it in GitHub Desktop.
Save jooyunghan/c540902cca7cd733cfa2c6f2f27ccf2f to your computer and use it in GitHub Desktop.
flatMap/map for JS Iterable(eg. Array, String)
const flatMap = (f, as) => {
const result = [];
for (const a of as) {
result.push(...f(a));
}
return result;
}
const map = (f, as) => {
const result = [];
for (const a of as) {
result.push(f(a));
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment