Skip to content
Snippets Groups Projects
Commit 700ee54d authored by Arkerthan's avatar Arkerthan
Browse files

Update random.js jsdoc

parent 427d3127
No related branches found
No related tags found
1 merge request!8958Fixes
......@@ -55,9 +55,10 @@ function jsRandom(min, max, count = 1) {
/**
* Chooses multiple random elements of an array.
* @param {number[]} arr
* @template {*} T
* @param {Array<T>} arr
* @param {number} count
* @returns {number[]}
* @returns {Array<T>}
*/
function jsRandomMany(arr, count) {
let result = [];
......@@ -71,15 +72,16 @@ function jsRandomMany(arr, count) {
/**
* Accepts both an array and a list, returns undefined if nothing is passed.
* @param {any[]} choices
* @param {any} [otherChoices]
* @returns {any}
* @template {*} T
* @param {Array<T>} choices
* @param {...T} [otherChoices]
* @returns {T}
*/
function jsEither(choices, ...otherChoices) {
if (otherChoices.length === 0 && Array.isArray(choices)) {
return choices[Math.floor(Math.random() * choices.length)];
}
const allChoices = otherChoices;
allChoices.push(choices);
allChoices.push(...choices);
return allChoices[Math.floor(Math.random() * allChoices.length)];
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment