ixfx
    Preparing search index...

    Function randomPluck

    • 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.

      Type Parameters

      • V

        Type of items in array

      Parameters

      • array: readonly V[] | V[]

        Array to pluck item from

      • mutate: boolean = false

        If true, changes input array. False by default.

      • rand: RandomSource = Math.random

        Random generatr. Math.random by default.

      Returns { array: V[]; value: undefined | V }

      Returns an object {value:V|undefined, array:V[]}

      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];