21 lines
662 B
TypeScript
21 lines
662 B
TypeScript
export class PointsTable {
|
|
private readonly pointsByPosition: Map<number, number>;
|
|
|
|
constructor(pointsByPosition: Record<number, number> | Map<number, number>) {
|
|
if (pointsByPosition instanceof Map) {
|
|
this.pointsByPosition = new Map(pointsByPosition);
|
|
} else {
|
|
this.pointsByPosition = new Map(
|
|
Object.entries(pointsByPosition).map(([key, value]) => [Number(key), value]),
|
|
);
|
|
}
|
|
}
|
|
|
|
getPointsForPosition(position: number): number {
|
|
if (!Number.isInteger(position) || position < 1) {
|
|
return 0;
|
|
}
|
|
const value = this.pointsByPosition.get(position);
|
|
return typeof value === 'number' ? value : 0;
|
|
}
|
|
} |