С
Math.floor(Math.random() * arr.length) >> 0
я так сделал, вроде не всегда срабатывает
Size: a a a
С
С
x
F
x
F
x
F
F
x
F
F
x
В
x
p
const arrayStr = ['one', 'two', 'three', 'four', 'five'];
const getRandom = arr => Math.floor(Math.random() * arr.length);
const swapWords = () => {
let arrCopy = [...arrayStr];
setInterval(() => {
const randomWord = arrCopy[getRandom(arrCopy)];
arrCopy = arrCopy.filter(x => x !== randomWord);
console.log(randomWord);
if (!arrCopy.length) {
console.log('-----')
arrCopy = [...arrayStr];
}
}, 500);
};
requestAnimationFrame(swapWords());
S
const arrayStr = ['one', 'two', 'three', 'four', 'five'];
const getRandom = arr => Math.floor(Math.random() * arr.length);
const swapWords = () => {
let arrCopy = [...arrayStr];
setInterval(() => {
const randomWord = arrCopy[getRandom(arrCopy)];
arrCopy = arrCopy.filter(x => x !== randomWord);
console.log(randomWord);
if (!arrCopy.length) {
console.log('-----')
arrCopy = [...arrayStr];
}
}, 500);
};
requestAnimationFrame(swapWords());
p
p
F