checkpoint

This commit is contained in:
2025-12-13 20:23:29 +01:00
parent 879db7e23b
commit 0d56d26afa
15 changed files with 250 additions and 35 deletions

View File

@@ -0,0 +1,43 @@
import type { Spending } from './Spending'
export class User {
name: string
spendings: Array<Spending>
constructor(name: string) {
this.name = name
this.spendings = Array<Spending>()
}
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()
}
}