@libshin/random-array

Shuffle and shorten an array.

Usage no npm install needed!

<script type="module">
  import libshinRandomArray from 'https://cdn.skypack.dev/@libshin/random-array';
</script>

README

TL;DR

Shuffle and shorten an array.

// randomArray(originArray)
randomArray([1, 2, 3, 4, 5, 6]);
// [4, 5, 3, 2, 1]

// randomArray(originArray, maxLength)
randomArray([1, 2, 3, 4, 5, 6], 2);
// [5, 3]

// randomArray(originArray, [minLength, maxLength])
randomArray([1, 2, 3, 4, 5, 6], [3, 5]);
// [4, 6, 2, 3]

Install

Browser

<script src="https://unpkg.com/@libshin/random-array(@version)/build/random-array.umd.js"></script>

You don't have to specify the version of the module. By default it will redirect to the latest version.

NPM

npm i --save @libshin/random-array

Yarn

yarn add @libshin/random-array

Import

Browser

const randomArray = window["@libshin/random-array"];

Node

const randomArray = require("@libshin/random-array");

ES Module

import randomArray from "@libshin/random-array";