@chriscodesthings/randomize-array
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

randomize-array
Test workflow status NPM Version License: MIT

Function to randomize an array

Description

Returns a copy of the array in a randomized order.

See...


Install

npm install --save @chriscodesthings/randomize-array

Usage

import randomizeArray from '@chriscodesthings/randomize-array';

console.log(randomizeArray([1, 2, 3, 4, 5]));
// => [3, 2, 5, 1, 4]

Syntax

randomizeArray(arr);

Parameters

  • arr: an array of things to randomize

Return Value

Returns a copy of arr in a random order.

Examples

// pick 2 security questions
function pickQuestions() {
    const questions = [
        "Favourite colour",
        "Favourite food",
        "Favourite place",
        "Favourite TV show",
        "Favourite song",
    ];

    return randomizeArray(questions).splice(-2);
}

See Also...

/@chriscodesthings/randomize-array/

    Package Sidebar

    Install

    npm i @chriscodesthings/randomize-array

    Weekly Downloads

    2

    Version

    1.1.1

    License

    MIT

    Unpacked Size

    6.06 kB

    Total Files

    8

    Last publish

    Collaborators

    • chriscodesthings