bitburner-src/src/Casino/CardDeck/Hand.ts
2021-09-04 19:09:30 -04:00

24 lines
484 B
TypeScript

/**
* Represents a Hand of cards.
*
* This class is IMMUTABLE
*/
import { Card } from "./Card";
export class Hand {
constructor(readonly cards: readonly Card[]) {}
addCards(...cards: Card[]): Hand {
return new Hand([...this.cards, ...cards]);
}
removeByIndex(i: number): Hand {
if (i >= this.cards.length) {
throw new Error(`Tried to remove invalid card from Hand by index: ${i}`);
}
return new Hand([...this.cards.slice().splice(i, 1)]);
}
}