This will be enough for you:
const randomLetters = "ljhgfdza";
const returnRandom = (randomString) => {
const arrString = [...randomString].sort((a, b) =>{
return 0.5 - Math.random()
}).join("");
console.log(typeof arrString,arrString);
}
returnRandom(randomLetters);
but… in this case sort
method is not that random as you think. This link will tell you why. I would do this with reduce()
or map()
, both are described in link above.
2
solved While loop and Strings [closed]