@chriscodesthings/randomize-array
v1.1.1
Published
Function to randomize an array
Downloads
9
Maintainers
Readme
randomize-array
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);
}