Skip to content

Instantly share code, notes, and snippets.

@JeffML
Created January 29, 2017 20:11
Show Gist options
  • Save JeffML/0cee0d09d32347ea95e0f9cb4f851cd8 to your computer and use it in GitHub Desktop.
Save JeffML/0cee0d09d32347ea95e0f9cb4f851cd8 to your computer and use it in GitHub Desktop.
var Combinator = function (opts) {
var combinations = [];
function combine(current, remainder) {
if (remainder.length === 0) {
if (current.length >= (opts.min || 0) &&
current.length <= (opts.max || current.length))
combinations.push(current);
} else {
combine(current.concat(remainder[0]), remainder.slice(1, remainder.length));
combine(current, remainder.slice(1, remainder.length));
}
return this;
}
return {
combinations: combinations,
combine: combine
}
}
module.exports = Combinator;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment