Skip to content
This repository was archived by the owner on Dec 30, 2023. It is now read-only.

Commit d09852c

Browse files
committed
fix(array/random): 🐛 Misleading condition
1 parent a91e3f1 commit d09852c

File tree

1 file changed

+1
-7
lines changed

1 file changed

+1
-7
lines changed

packages/array/source/random/random.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,7 @@ export async function getRandomIndex(length: number): Promise<number> {
1010
export async function getRandomItem<Type = unknown>(array: Array<Type> | readonly Type[]): Promise<Type> {
1111
validateArray(array);
1212

13-
const item = array.at(await getRandomIndex(array.length));
14-
15-
if (item) {
16-
return item;
17-
} else {
18-
throw new TypeError(`Something went wrong with obtaining a random array item.`);
19-
}
13+
return array.at(await getRandomIndex(array.length)) as Type;
2014
}
2115

2216
interface RandomArrayItemsOptions {

0 commit comments

Comments
 (0)