Skip to content

Instantly share code, notes, and snippets.

@yalovek
Last active March 30, 2019 04:42
Show Gist options
  • Save yalovek/7c630a2a1aad3dbfa6d71c2fada24705 to your computer and use it in GitHub Desktop.
Save yalovek/7c630a2a1aad3dbfa6d71c2fada24705 to your computer and use it in GitHub Desktop.
Iterate arrays
(function(cb, ...params) {
const last = params.length - 1;
const count = params[last] - 1;
function iterate(c, values) {
params[c].forEach(function(item) {
if (c === count) {
cb(...values, item);
} else {
iterate(c + 1, [...values, item]);
}
});
}
iterate(0, []);
})(console.log, [1,2,6,7], [3,4,5], [8,9], 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment