Skip to content

Instantly share code, notes, and snippets.

@bericp1
Created November 23, 2015 22:58
Show Gist options
  • Save bericp1/f0aa66e57ed0a5707368 to your computer and use it in GitHub Desktop.
Save bericp1/f0aa66e57ed0a5707368 to your computer and use it in GitHub Desktop.
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