Created
September 12, 2015 17:03
-
-
Save apnerve/dd10e5758f9a640f5ea9 to your computer and use it in GitHub Desktop.
Where am I spending my money?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var sc = require('sc-card-transaction-parser'); | |
var _ = require('lodash'); | |
var file = fs.readFileSync('transactions.txt'); | |
var transactions = sc.parseLog(file); | |
var expenses = function(data, type) { | |
var grouped = _.groupBy(data, type); | |
return _.keys(grouped).map(function(a) { | |
return { | |
type: a, | |
amount: _.round(_.sum(grouped[a], 'amount'), 2) | |
}; | |
}); | |
} | |
console.log(_.sortBy(expenses(transactions,'desc'), function(a) { | |
return a.amount; | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment