Files: ecf6563965cf3a734a59dfba74cd29977efbe9d6 / src / index.js
587 bytesRaw
1 | const { readBlock, writeBlock } = require('./domain/block'); |
2 | |
3 | /* |
4 | * data {string} - Data to be parsed |
5 | */ |
6 | module.exports = function process(lines) { |
7 | const groupsArr = readBlock(lines); |
8 | |
9 | // Calculate total of each group |
10 | const groupsWithTotals = groupsArr.map(g => ({ |
11 | ...g, |
12 | total: g.records.reduce((total, record) => total + record.value, g.total), |
13 | })); |
14 | |
15 | // Calculate balance |
16 | const balance = groupsWithTotals.reduce((balance, g) => { |
17 | if (g.ignoreInBalance) return balance; |
18 | |
19 | return balance + g.total; |
20 | }, 0); |
21 | |
22 | return writeBlock(balance, groupsWithTotals); |
23 | }; |
24 |
Built with git-ssb-web