Skip to content

Instantly share code, notes, and snippets.

@vasanthv
Last active May 30, 2019 07:28
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 vasanthv/272dd3676a971567f943c62490edce51 to your computer and use it in GitHub Desktop.
Save vasanthv/272dd3676a971567f943c62490edce51 to your computer and use it in GitHub Desktop.
A function to get all possible combination of arrays.
const arr = [ [ '8', '0', '5', '7', '9' ], [ '1', '2', '4' ] ]
const output = arr.reduce((a, b) => {
let ret = [];
a.forEach(i => b.forEach(j => ret.push(i + j)));
return ret;
});
// output = [ '81', '82', '84', '01', '02', '04', '51', '52', '54', '71', '72', '74', '91', '92', '94' ];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment