mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-09-22 22:00:57 +02:00
24 lines
484 B
TypeScript
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)]);
|
|
}
|
|
}
|