File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- export * from './lib/ensure-http-prefix' ;
21export * from './lib/array-sum' ;
2+ export * from './lib/array-random-element' ;
33export * from './lib/average' ;
44export * from './lib/build-query-string' ;
55export * from './lib/camel-to-snake-case' ;
@@ -9,6 +9,7 @@ export * from './lib/convert-to-hex';
99export * from './lib/deduplicate' ;
1010export * from './lib/deep-clone' ;
1111export * from './lib/deep-merge' ;
12+ export * from './lib/ensure-http-prefix' ;
1213export * from './lib/generate-encryption-key' ;
1314export * from './lib/generate-sha256-hash' ;
1415export * from './lib/extract-name-from-email' ;
Original file line number Diff line number Diff line change 1+ /**
2+ * Returns a random element from an array.
3+ *
4+ * @param array - The array to select an element from.
5+ * @returns A random element from the array, or `null` if the array is empty.
6+ */
7+ export function getRandomElement < T > ( array : T [ ] ) : T | null {
8+ if ( ! Array . isArray ( array ) || array . length === 0 ) {
9+ return null ; // Return null if the array is empty or not valid
10+ }
11+
12+ const randomIndex = Math . floor ( Math . random ( ) * array . length ) ;
13+ return array [ randomIndex ] ;
14+ }
You can’t perform that action at this time.
0 commit comments