ixfx
    Preparing search index...

    Function sample

    • Samples values from an array.

      If amount is less or equal to 1, it's treated as a percentage to sample. Otherwise it's treated as every _n_th value to sample.

      Type Parameters

      • V

      Parameters

      • array: ArrayLike<V>

        Array to sample

      • amount: number

        Amount, given as a percentage (0..1) or the number of interval (ie 3 for every third item)

      Returns V[]

      By percentage - get half of the items

      const list = [1,2,3,4,5,6,7,8,9,10];
      const sub = Arrays.sample(list, 0.5);
      // Yields: [2, 4, 6, 8, 10]

      By steps - every third value

      const list = [1,2,3,4,5,6,7,8,9,10];
      const sub = Arrays.sample(list, 3);
      // Yields:
      // [3, 6, 9]