forked from Disciplr-Org/Disciplr-Frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtxTotals.ts
More file actions
31 lines (28 loc) · 733 Bytes
/
Copy pathtxTotals.ts
File metadata and controls
31 lines (28 loc) · 733 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* Computes aggregate totals (count, sum amount, sum fees) from a list of
* transaction-like objects. Pure function, no side-effects.
*/
export interface TxTotals {
count: number;
totalAmount: number;
totalFees: number;
}
/**
* Sum `amount` and `fee` across an array of transaction-like objects.
* Returns zeroed totals for an empty array.
*/
export function computeTxTotals(
transactions: ReadonlyArray<{ amount: number; fee: number }>,
): TxTotals {
let totalAmount = 0;
let totalFees = 0;
for (let i = 0; i < transactions.length; i++) {
totalAmount += transactions[i].amount;
totalFees += transactions[i].fee;
}
return {
count: transactions.length,
totalAmount,
totalFees,
};
}