Skip to content

Instantly share code, notes, and snippets.

@dosjota
Created April 20, 2017 15:42
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 dosjota/bfc81650e96161f4e58028ef9072ecac to your computer and use it in GitHub Desktop.
Save dosjota/bfc81650e96161f4e58028ef9072ecac to your computer and use it in GitHub Desktop.
Permutacion de Array List
var lista = [[1,3],['a'],[4,5]]
var perm = (array, prefix = '')=>{
if (!array.length) {
return prefix
}
let resultado = array[0].reduce((resultado, valor) => {
return resultado.concat(perm(array.slice(1), prefix + valor))
}, []);
return resultado
}
var resultadoPerm = perm(lista), resultadoFinal = []
for (var i = 0; i < resultadoPerm.length; i++) {
resultadoFinal.push(resultadoPerm[i].split(""))
}
for(let r of resultadoFinal){
console.log(r);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment