Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/fathym_common/src/src.deps.ts>sample

The Fathym Reference Architecture provides the common foundation for applications built in Typescript.
Go to Latest
function sample
import { sample } from "https://deno.land/x/fathym_common@v0.0.143/src/src.deps.ts";

Returns a random element from the given array.

Examples

Example 1

import { sample } from "https://deno.land/std@0.224.0/collections/sample.ts";
import { assert } from "https://deno.land/std@0.224.0/assert/assert.ts";

const numbers = [1, 2, 3, 4];
const random = sample(numbers);

assert(numbers.includes(random as number));

Parameters

array: readonly T[]

Returns

T | undefined