Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created December 10, 2021 01:03
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/ee0864b033b9ec9089ec7f934c2e812e to your computer and use it in GitHub Desktop.
Save parzibyte/ee0864b033b9ec9089ec7f934c2e812e 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;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment