Cargando contenido...
const anagram = (txt) => {
let out = ''; // iniciamos string vacio
Array.from(txt.split(' ')).forEach(item => {
let word = '';
let firstLetter = item[0]; // obtenemos la primera letra
item = item.substr(1).split(''); // separamos las palabras
while (item.length > 0) {
// movemos las letras de cada palabra aleatoriamente
word += item.splice(item.length * Math.random() << 0, 1);
}
// juntamos todo en el string
out += firstLetter + word + " ";
});
return out;
}
let txt = '';
for(let i = 0; i < 6; i++){
txt += anagram('LOGOPEDA');
}
console.log(txt)
// "LGOOAEPD LADPOGOE LOAGOEPD LAODEPOG LODEPOGA LDOOAGPE "
Pruébalo en Termx