Created
April 3, 2019 19:22
-
-
Save 7rulnik/8a00995baba6c2eda825f46a65cd7c9c to your computer and use it in GitHub Desktop.
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
const fs = require('fs') | |
const papaparse = require('papaparse') | |
// нужно вырезать строку с названием стоблцов | |
const csv = fs.readFileSync('./2018.csv', 'utf8') | |
const { data } = papaparse.parse(csv) | |
const realCashback = data.reduce((acc, item) => { | |
const cashback = parsePrice(item[12]) | |
return acc + cashback | |
}, 0) | |
const operationsWithLargerCashback = [] | |
const potentialCashback = data.reduce((acc, item) => { | |
const price = parsePrice(item[6]) | |
const cashback = parsePrice(item[12]) | |
if (cashback === 0 || price > 0) return acc | |
const category = item[9] | |
const ratio = category === 'Авиабилеты' ? 0.03 : 0.02 | |
const allAirlinesCachback = Math.floor(price * ratio * -1) | |
if (allAirlinesCachback < cashback) operationsWithLargerCashback.push(item) | |
return acc + allAirlinesCachback | |
}, 0) | |
console.log({ | |
realCashback, | |
potentialCashback, | |
}) | |
function parsePrice(number) { | |
return parseFloat(number.replace(',', '.')) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment