Skip to content

Instantly share code, notes, and snippets.

@gilesbradshaw
Created December 1, 2017 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gilesbradshaw/2a0207b00d77a730681c064f701b881b to your computer and use it in GitHub Desktop.
Save gilesbradshaw/2a0207b00d77a730681c064f701b881b to your computer and use it in GitHub Desktop.
function selectMany(func) {
return this.reduce(
(acc, val) => [
...acc,
...func(val),
],
[],
);
}
['josh', 'steve', 'steve', 'craig']::selectMany(x => [x, `hello ${x}']);
/* [
'josh',
'hello josh',
'steve',
'hello steve',
...etc
]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment