Skip to content

Commit

Permalink
fix: Simplify preplayRandom method in Group class
Browse files Browse the repository at this point in the history
  • Loading branch information
ctoth committed Aug 21, 2024
1 parent 3f6739a commit c3225d1
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions src/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ export class Group implements BaseSound {
* @throws Error if the group is empty and there are no sounds to prepare.
*/
preplayRandom(): Playback {
if (this.sounds.length === 0) {
throw new Error("Cannot prepare a random sound from an empty group");
}
const randomIndex = Math.floor(Math.random() * this.sounds.length);
const randomSound = this.sounds[randomIndex] as Sound;
const randomSound = this.randomSound();
const playback = randomSound.preplay();
return playback[0];
}
Expand Down

0 comments on commit c3225d1

Please sign in to comment.