Last active
March 30, 2019 04:42
-
-
Save yalovek/7c630a2a1aad3dbfa6d71c2fada24705 to your computer and use it in GitHub Desktop.
Iterate arrays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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