import getRandomNumber from "./get_random_number"; import swapArrayElements from "./swap_array_elements"; function* sample(input: any[], amount: number) { const temp = Array.from(input); while (amount > 0 && temp.length) { swapArrayElements( temp, getRandomNumber(0, temp.length - 1), temp.length - 1 ); yield temp.pop(); amount = amount - 1; } } export default function shuffleArray(input: any[]) { return Array.from(sample(input, input.length)); }