Skip to content

Instantly share code, notes, and snippets.

Created March 20, 2017 13:15
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Generate all possible words with a given set of characters
function allPossibleCombinations(input, fixedLength, currentCombination) {
if (currentCombination.length == fixedLength) {
return [currentCombination];
const combinations = [];
for (let i = 0; i < input.length; i++) {
combinations.push(...allPossibleCombinations(input, fixedLength, currentCombination + input[i]));
return combinations;
const input = ['a', '1'];
console.log(allPossibleCombinations(input, 2, '')); // ['aa', 'a1', '1a', '11']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment