Add weightedSample snippet
This commit is contained in:
@ -5470,6 +5470,22 @@
|
||||
"hash": "a2c8560a2e285ebe11caad3a46c07ee0e41a64bd850b2e5a4f5aebc12da09dcc"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "weightedSample",
|
||||
"type": "snippetListing",
|
||||
"title": "weightedSample",
|
||||
"attributes": {
|
||||
"text": "Returns a random element from an array, using the provided `weights` as the probabilities for each element.\n\nUse `Array.prototype.reduce()` to create an array of partial sums for each value in `weights`.\nUse `Math.random()` to generate a random number and `Array.prototype.findIndex()` to find the correct index based on the array previously produced.\nFinally, return the element of `arr` with the produced index.\n\n\n",
|
||||
"tags": [
|
||||
"array",
|
||||
"random",
|
||||
"advanced"
|
||||
]
|
||||
},
|
||||
"meta": {
|
||||
"hash": "6bba5ca7427489cdf18476542772743ae2d5f4eccb42ff93ee61b9f8ba1f55d6"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "when",
|
||||
"type": "snippetListing",
|
||||
|
||||
Reference in New Issue
Block a user