UNPKG

algorithmpool

Version:
13 lines (12 loc) 319 B
import { swap } from '../../utils/util'; export const shuffle = (array) => { let currentIndex = array.length; while (currentIndex !== 0) { const randomIndex = Math.floor(Math.random() * currentIndex); currentIndex--; swap(array, currentIndex, randomIndex); } return array; }