@bytebury/sauce - v1.13.0
    Preparing search index...

    Function sample

    • Pick a random item from an array.

      Type Parameters

      • T

      Parameters

      • list: T[]

      Returns Option<T>

      This will always return None if the list is empty.

      const myList = [1, 2, 3, 4];
      const randomItem = sample(myList);

      if (randomItem.isSome()) {
      console.log(randomItem.unwrap()); // could be 1, 2, 3, or 4
      } else {
      console.log('No item found');
      }