Created
April 20, 2017 15:42
-
-
Save dosjota/bfc81650e96161f4e58028ef9072ecac to your computer and use it in GitHub Desktop.
Permutacion de Array List
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
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