0.0.1 • Published 9 years ago

randomarray v0.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

RandomArray

An extension of JavaScript's Array for handling array randomly.

Main

dist/
└── randomarray.js  (2 KB)

Getting started

Quick start

Three quick start options are available:

  • Download the latest release.
  • Clone the repository: git clone https://github.com/fengyuanchen/randomarray.git.
  • Install with NPM: npm install randomarray.

Usage

Browser

<script scr="/path/to/randomarray.js"></script>
const arr = new RandomArray(1, 2, 3);

arr.random(); // 1 or 2 or 3

NodeJS

const RandomArray = require("randomarray");
const arr = new RandomArray(1, 2, 3);

arr.random(); // 1 or 2 or 3

Methods

random(element)

Get a random element from an array, or replace a random element of an array with a new element and return the array.

randomSort()

Sort the elements of an array randomly and return the array.

randomPush(element1, ..., elementN)

Add one or more elements to one or some random positions of an array and return the new length of the array.

randomUnshift(element1, ..., elementN)

The same as randomPush.

randomPop()

Remove a random element from an array and return the removed element.

randomShift()

The same as randomPop.

Browser Support

  • Chrome 43+
  • Chrome for Android 43+
  • Android Webview 43+

Node.js Support

  • io.js v2.3.4+

License

Released under the MIT license.