Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created December 10, 2021 01:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/2b779afa1d8aca22d388f2d55ce87af2 to your computer and use it in GitHub Desktop.
Save parzibyte/2b779afa1d8aca22d388f2d55ce87af2 to your computer and use it in GitHub Desktop.
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