-
-
Save parzibyte/2b779afa1d8aca22d388f2d55ce87af2 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
const obtenerCombinaciones = palabra => { | |
// https://parzibyte.me/blog | |
const combinaciones = []; | |
for (let i = 0; i < palabra.length; i++) { | |
// Primero la letra actual | |
let combinacion = palabra.charAt(i); | |
combinaciones.push(combinacion); | |
for (let j = i + 1; j < palabra.length; j++) { | |
combinacion += palabra.charAt(j); | |
// Y luego lo de la primera letra con todas las que le siguen hasta el final | |
combinaciones.push(combinacion); | |
} | |
} | |
return combinaciones; | |
}; | |
const palabras = ["Luis", "Pan", "JavaScript", "Python"]; | |
for (const palabra of palabras) { | |
const combinaciones = obtenerCombinaciones(palabra); | |
console.log("Las combinaciones de '%s' son:", palabra); | |
for (const combinacion of combinaciones) { | |
console.log(combinacion); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment