Completed the assignment
This commit is contained in:
parent
79e11d88ad
commit
b7c73fc964
|
@ -9,12 +9,9 @@ const {
|
|||
const results = [], amountStore = {};
|
||||
|
||||
async function calculate(file, tokens, date) {
|
||||
let tokenArr = tokens.split(',')
|
||||
const USDConvStore = await getRates(tokenArr);
|
||||
|
||||
function USDConvStoreFn(parentCurreny, value){
|
||||
const ans = value / USDConvStore[parentCurreny]
|
||||
return ans.toFixed(2)
|
||||
let tokenArr
|
||||
if(tokens) {
|
||||
tokenArr = tokens.split(',')
|
||||
}
|
||||
|
||||
let dateToEpoch
|
||||
|
@ -25,6 +22,7 @@ async function calculate(file, tokens, date) {
|
|||
fs.createReadStream(file)
|
||||
.pipe(csv())
|
||||
.on('data', (data) => {
|
||||
|
||||
if(dateToEpoch){
|
||||
if(data.timestamp > dateToEpoch){
|
||||
results.push(data);
|
||||
|
@ -36,8 +34,17 @@ async function calculate(file, tokens, date) {
|
|||
results.push(data);
|
||||
}
|
||||
})
|
||||
.on('end', () => {
|
||||
.on('end', async () => {
|
||||
const uniqueCoins = [...new Set(results.map(item => item.token))];
|
||||
if(!tokens){
|
||||
tokenArr = uniqueCoins
|
||||
}
|
||||
const USDConvStore = await getRates(tokenArr);
|
||||
|
||||
function USDConvStoreFn(parentCurreny, value){
|
||||
const ans = value / USDConvStore[parentCurreny]
|
||||
return ans.toFixed(2)
|
||||
}
|
||||
|
||||
uniqueCoins.forEach(coin => {
|
||||
amountStore[coin] = 0
|
||||
|
|
Loading…
Reference in New Issue