Created
November 23, 2015 23:04
-
-
Save bericp1/f3a1ddf27714f3482a47 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 = []; | |
if(word.length >= 3) { | |
combos.push(word); | |
} | |
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 = _.uniq(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