Created
January 29, 2017 21:16
-
-
Save JeffML/2436938b896f4930874676cd9eeb019f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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