JSPM

@chriscodesthings/randomize-array

1.1.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q34176F
  • License MIT

Function to randomize an array

Package Exports

  • @chriscodesthings/randomize-array
  • @chriscodesthings/randomize-array/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@chriscodesthings/randomize-array) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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