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

https://github.com/hugoalh-studio/shuffle-array-js

A JavaScript module to shuffle the array's indexes.
https://github.com/hugoalh-studio/shuffle-array-js

array javascript js shuffle

Last synced: 3 months ago
JSON representation

A JavaScript module to shuffle the array's indexes.

Awesome Lists containing this project

README

          

# Shuffle Array (JavaScript)

[**âš–ī¸** MIT](./LICENSE.md)

**đŸ—‚ī¸**
[![GitHub: hugoalh-studio/shuffle-array-js](https://img.shields.io/badge/hugoalh--studio/shuffle--array--js-181717?logo=github&logoColor=ffffff&style=flat "GitHub: hugoalh-studio/shuffle-array-js")](https://github.com/hugoalh-studio/shuffle-array-js)
[![NPM: @hugoalh/shuffle-array](https://img.shields.io/badge/@hugoalh/shuffle--array-CB3837?logo=npm&logoColor=ffffff&style=flat "NPM: @hugoalh/shuffle-array")](https://www.npmjs.com/package/@hugoalh/shuffle-array)

**🆙** ![Latest Release Version](https://img.shields.io/github/release/hugoalh-studio/shuffle-array-js?sort=semver&color=2187C0&label=&style=flat "Latest Release Version") (![Latest Release Date](https://img.shields.io/github/release-date/hugoalh-studio/shuffle-array-js?color=2187C0&label=&style=flat "Latest Release Date"))

A JavaScript module to shuffle the array's indexes.

## đŸŽ¯ Target

- Bun ^ v1.0.0
- Cloudflare Workers
- Deno >= v1.34.0
> **đŸ›Ąī¸ Require Permission**
>
> *N/A*
- NodeJS >= v16.13.0

### 🔗 Other Edition

- [TypeScript](https://github.com/hugoalh-studio/shuffle-array-ts)

## 🔰 Usage

### Via Installation

> **đŸŽ¯ Supported Target**
>
> - Cloudflare Workers
> - NodeJS

1. Install via console/shell/terminal:
- Via NPM
```sh
npm install @hugoalh/shuffle-array[@]
```
- Via PNPM
```sh
pnpm add @hugoalh/shuffle-array[@]
```
- Via Yarn
```sh
yarn add @hugoalh/shuffle-array[@]
```
2. Import at the script (`.js`):
```js
import ... from "@hugoalh/shuffle-array";
```
> **â„šī¸ Note**
>
> Although it is recommended to import the entire module, it is also able to import part of the module with sub path if available, please visit [file `package.json`](./package.json) property `exports` for available sub paths.

### Via NPM Specifier

> **đŸŽ¯ Supported Target**
>
> - Bun
> - Deno

1. Import at the script (`.js`):
```js
import ... from "npm:@hugoalh/shuffle-array[@]";
```
> **â„šī¸ Note**
>
> Although it is recommended to import the entire module, it is also able to import part of the module with sub path if available, please visit [file `package.json`](./package.json) property `exports` for available sub paths.

## 🧩 API

- ```ts
function shuffleArray(item: T[]): T[];
```

## âœī¸ Example

- ```js
const chain = [3, 7, 25, 26, 42, 62, 71, 76, 92, 93];

shuffleArray(chain);
//=> [62, 93, 26, 42, 25, 7, 76, 71, 3, 92]

shuffleArray(chain);
//=> [42, 3, 26, 62, 93, 7, 76, 25, 92, 71]
```