From 2f2d4adb43da21a953b7baa488ae520e58c5a15e Mon Sep 17 00:00:00 2001 From: Tony Li Date: Sat, 17 Sep 2016 15:32:41 -0400 Subject: [PATCH] HelenPark` --- index.js | 23 +++++++++++++++++++++++ package.json | 15 +++++++++++++++ test-0.csv | 6 ++++++ 3 files changed, 44 insertions(+) create mode 100644 index.js create mode 100644 package.json create mode 100644 test-0.csv diff --git a/index.js b/index.js new file mode 100644 index 0000000..23d4ad0 --- /dev/null +++ b/index.js @@ -0,0 +1,23 @@ +var fs = require('fs'); +var _ = require('lodash'); + +var pastValue = -1; +var tally = 1; +var fn = process.argv[2]; +// date, market value, cash flow +_.forEach(fs.readFileSync(fn, 'utf8').split('\r\n'), function (line) { + var curLine = _.map(line.split(','), function (item) { + return parseInt(item); + }); + + if (curLine.length < 3) return; + + if (pastValue === -1) { + pastValue = curLine[2]; + } else { + tally *= (curLine[2] - curLine[1])/pastValue; + pastValue = curLine[2]; + } +}); + +console.log(tally); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..5234fc3 --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "name": "wealth", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "fs": "0.0.1-security", + "lodash": "^4.15.0" + } +} diff --git a/test-0.csv b/test-0.csv new file mode 100644 index 0000000..97a5ee3 --- /dev/null +++ b/test-0.csv @@ -0,0 +1,6 @@ +2016-06-08,0.0,100.0 +2016-06-09,0.0,101.1 +2016-06-10,0.0,102.4 +2016-06-11,0.0,105.2 +2016-06-12,0.0,105.3 +2016-06-13,0.0,105.9