git ssb

0+

Rômulo Alves / money-block



Tree: 5d6d0b006184c1e4af203d97238bda40d3ac0cad

Files: 5d6d0b006184c1e4af203d97238bda40d3ac0cad / src / index.js

587 bytesRaw
1const { readBlock, writeBlock } = require('./domain/block');
2
3/*
4 * data {string} - Data to be parsed
5 */
6module.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