const csv = "date,open,high,low,close\n31/10/2019,9202.457589,9383.160892,9028.71744,9199.584833\n30/10/2019,9422.463325,9426.874217,9085.370357,9205.726559\n29/10/2019,9248.440562,9516.181048,9232.648086,9427.687584\n28/10/2019,9565.101883,9805.118089,9256.148389,9256.148389"
const lines = csv.split(/[\r?\n|\r|\n]+/)
const header = lines.shift().split(',') // chop off header, and store it in a variable
const cells = lines.map(e => e.split(',').map(n => !isNaN(n) ? Number(n) : n))
// transpose the array, so it's easier to get min/max
// transposing (rows become columns and columns become rows)
// [[a, b],[c, d]] ==> [[a, c], [b, d]]
const transpose = cells[0].map((e, i) => {
return cells.map(el => {
return el[i]
})
})
const dates = transpose.shift() // chop off dates, and store them in a variable
const rowRange = transpose.map((e, i) => {
const min = Math.min(...e)
const max = Math.max(...e)
return {
col: i + 1, // +1, because dates are chopped off
colName: header[i + 1],
max,
maxRow: e.indexOf(max) + 1, // +1, because header is chopped off
maxRowDate: dates[e.indexOf(max)],
min,
minRow: e.indexOf(min) + 1, // +1, because header is chopped off
minRowDate: dates[e.indexOf(min)]
}
})
console.log("result:", rowRange)