Skip to main content

shuffle

Randomly shuffles the order of elements in an array.


Code

🔗 View source code


Benchmark

  • hz: Operations per second
  • mean: Average response time (ms)
NamehzmeanPerformance
modern-kit/shuffle2,874,351.450.0003fastest
lodash/shuffle1,895,677.790.0005slowest
  • modern-kit/shuffle
    • 1.52x faster than lodash/shuffle

Interface

typescript
function shuffle<T>(arr: T[] | readonly T[]): T[]

Usage

typescript
import { shuffle } from '@modern-kit/utils';

shuffle([1, 2, 3, 4, 5]); // Returns a randomly shuffled array, e.g: [3, 5, 1, 3, 2]