Last active
December 4, 2024 03:57
-
-
Save mflorida/822f04f0a1f4534b26c8e13c730be103 to your computer and use it in GitHub Desktop.
Pick random item from array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Pick random item from an iterable object | |
* @param {string|Array|Map|Iterable} items | |
* @returns {*} | |
*/ | |
export function pickRandom(items) { | |
return [...items][Math.floor(Math.random() * (items.length))]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment