Removes a random item from an array, returning both the item and the new array as a result. Does not modify the original array unless mutate parameter is true.
mutate
import { Arrays } from 'https://unpkg.com/ixfx/dist/data.js';const data = [100, 20, 40];const {value, array} = Arrays.randomPluck(data);// value: 20, array: [100, 40], data: [100, 20, 40]; Copy
import { Arrays } from 'https://unpkg.com/ixfx/dist/data.js';const data = [100, 20, 40];const {value, array} = Arrays.randomPluck(data);// value: 20, array: [100, 40], data: [100, 20, 40];
import { Arrays } from 'https://unpkg.com/ixfx/dist/data.js';const data = [100, 20, 40];const {value} = Arrays.randomPluck(data, true);// value: 20, data: [100, 40]; Copy
import { Arrays } from 'https://unpkg.com/ixfx/dist/data.js';const data = [100, 20, 40];const {value} = Arrays.randomPluck(data, true);// value: 20, data: [100, 40];
Type of items in array
Array to pluck item from
If true, changes input array. False by default.
Random generatr. Math.random by default.
Math.random
Returns an object {value:V|undefined, array:V[]}
{value:V|undefined, array:V[]}
Readonly
Removes a random item from an array, returning both the item and the new array as a result. Does not modify the original array unless
mutate
parameter is true.Example: Without changing source
Example: Mutating source