Created
January 29, 2017 20:11
-
-
Save JeffML/0cee0d09d32347ea95e0f9cb4f851cd8 to your computer and use it in GitHub Desktop.
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
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