function permutations(word){ if(word.length <=1) return [word]; if(typeof word === 'string'){ word = word.split('') } if(typeof word === 'number'){ word = String(word).split('') } let permutationCollection = []; let nextWord = []; let characters = []; permute(word); return permutationCollection function permute(characters){ if(characters.length < 1){ // add word to permutations array permutationCollection.push(nextWord.join('')); } for(let i = 0; i < characters.length; i++){ characters.push(characters.shift()); nextWord.push(characters[0]) permute(characters.slice(1);); nextWord.pop(); } } }