Created
November 23, 2015 22:58
-
-
Save bericp1/f0aa66e57ed0a5707368 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 choices = ['1', '2', '3'], | |
combos = [], | |
_ = require('underscore'); | |
var addLetter = function(word) { | |
var combos = []; | |
choices.forEach(function(choice) { | |
combos.push(word + choice); | |
}); | |
return combos; | |
}; | |
combos = addLetter(''); | |
for(i=0; i < 5; i++) { | |
combos = combos.map(addLetter); | |
combos = _.flatten(combos); | |
} | |
combos = combos.filter(function(combo) { | |
return combo.indexOf('1') != -1 && combo.indexOf('2') != -1 && combo.indexOf('3') != -1 | |
}); | |
console.log('combos:', combos); | |
console.log('count:', combos.length); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment