Solución
solution.tsTypeScript
export function getBalance(initialBalance: number, depositAmount: number): number {
// Crea una BankAccount con private balance y retorna el saldo tras el depósito
class BankAccount {
private balance: number;
constructor(initial: number) {
this.balance = initial;
}
deposit(amount: number): void {
this.balance += amount;
}
getBalance(): number {
return this.balance;
}
}
const newAccount = new BankAccount(initialBalance);
newAccount.deposit(depositAmount);
return newAccount.getBalance();
// return initialBalance + depositAmount;
}
0respuestas