1.1.1 • Published 1 year ago

@chriscodesthings/randomize-array v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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...