Published on

Shuffle an array

Simple array shuffling function

const shuffle = arr => arr.sort(() => 0.5 - Math.random());

Usage

shuffle([1, 2, 3, 4, 5])
// [3, 2, 5, 4, 1]
shuffle([1, 2, 3, 4, 5])
// [3, 1, 5, 4, 2]
shuffle(['foo', 'bar', 'buzz'])
// ['buzz', 'bar', 'foo']