An open API service indexing awesome lists of open source software.

https://github.com/kimmelsg/array-shuffle

Fisher-Yates shuffle of an array of items producing an unbiased permutation.
https://github.com/kimmelsg/array-shuffle

Last synced: 2 months ago
JSON representation

Fisher-Yates shuffle of an array of items producing an unbiased permutation.

Awesome Lists containing this project

README

        

# array-shuffle [![Build Status](https://travis-ci.org/kimmelsg/array-shuffle.svg?branch=master)](https://travis-ci.org/kimmelsg/array-shuffle) [![codecov](https://codecov.io/gh/kimmelsg/array-shuffle/badge.svg?branch=master)](https://codecov.io/gh/kimmelsg/array-shuffle?branch=master)

> [Fisher-Yates](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle) shuffle of an array of items producing an unbiased permutation.

## Install

```
$ npm install @kimmel/array-shuffle
```

## Usage

```js
import shuffle from '@kimmel/array-shuffle';

const shuffledArray = shuffle([1, 2, 3, 4, 5, 6]);
//=> [3, 1, 2, 5, 6, 4]
```

`shuffle` does _not_ mutate the original array.

## API

### shuffle(items)

#### items

Type: `array`

`['hello', 2, 5, { foo: 'bar' }]`

## License

MIT © [Ryan Castner](https://kimmel.com)