Skip to content

Instantly share code, notes, and snippets.

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