Skip to content

Instantly share code, notes, and snippets.

@7rulnik
Created April 3, 2019 19:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 7rulnik/8a00995baba6c2eda825f46a65cd7c9c to your computer and use it in GitHub Desktop.
Save 7rulnik/8a00995baba6c2eda825f46a65cd7c9c to your computer and use it in GitHub Desktop.
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