es-toolkit
Version:
A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.
16 lines (13 loc) • 423 B
JavaScript
import { sample as sample$1 } from '../../array/sample.mjs';
import { toArray } from '../_internal/toArray.mjs';
import { isArrayLike } from '../predicate/isArrayLike.mjs';
function sample(collection) {
if (collection == null) {
return undefined;
}
if (isArrayLike(collection)) {
return sample$1(toArray(collection));
}
return sample$1(Object.values(collection));
}
export { sample };