import type { Spending } from './Spending' export class User { name: string spendings: Array constructor(name: string) { this.name = name this.spendings = Array() } addSpending(spending: Spending): void { spending.setSpender(this) this.spendings.push(spending) } getTotalSpending(): number { return this.spendings.map((w) => w.amountCt).reduce((acc, num) => acc + num, 0) } getInitials(): string { if (!this.name) return '' const words = this.name .trim() .split(/\s+/) .filter((word) => word.length > 0) if (words.length === 0) return '' if (words.length === 1) { const firstWord = words[0] if (!firstWord || firstWord.length === 0) return '' return firstWord.substring(0, 2).toUpperCase() } const firstWord = words[0] const secondWord = words[1] if (!firstWord || !secondWord || firstWord.length === 0 || secondWord.length === 0) return '' return (firstWord[0]! + secondWord[0]!).toUpperCase() } }