Generation

generate functionMon, 10 Jul 2023

Una función que muestre todas las posibles permutaciones de una palabra que recibe como parametro

function permute(word) { let result = []; if (word.length <= 1) { return [word]; } for (let i = 0; i < word.length; i++) { let firstChar = word[i]; let otherChars = word.substring(0, i) + word.substring(i + 1); let otherPermutations = permute(otherChars); for (let j = 0; j < otherPermutations.length; j++) { result.push(firstChar + otherPermutations[j]); } } return result; }

Javascript
Generate More

Want to kickstart your project?Use the new AI Studio to create your code