Files: 66b5635a9a864ebf035dcd24a8011a13f5d9f323 / 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