JSFiddle - React, Tailwind, and code Playground
by Daedalus
JavaScript
let list = "GirlElf,Death,Daedalus,Sapph,Blackfyre,Agatha".split(","),
list2 = {};
function shuffle(arr, ret) {
let r1 = arr[Math.floor(Math.random() * arr.length)];
if (typeof ret[r1] === 'undefined') {
let r2 = arr[Math.floor(Math.random() * arr.length)];
do {
ret[r1] = r2;
if (r1 === r2) {
r2 = arr[Math.floor(Math.random() * arr.length)];
} else {
ret[r1] = r2;
break;
}
} while (r1 === r2);
}
if (Object.keys(ret).length < arr.length) {
console.log(arr.length);
}
return ret;
}
console.log(shuffle(list, list2));