问题
I want to find the row value of Math.min but I have no idea how to find this even though I have googled for a few days.
Can someone tell how to solve this issue?
function getDataPointsFromCSV(csv) {
var dataPoints = csvLines = [];
var price;
var lowestv = Infinity;
<!-- read csv file
csvLines = csv.split(/[\r?\n|\r|\n]+/);
<!-- read row 1-10
for (var i = 1; i <= 10; i++)
if (csvLines[i].length > 0) {
<!-- read csv file
points = csvLines[i].split(",");
<!-- read the data from points[4]=(coloumn5)
price = points[4]
<!-- find the row number which store lowest value in a coloumn
lowestv = Math.min(price, lowestv)
<!-- fault example; the value that I want to find is lowestv.length
for (var i = lowestv.length; i <= lowestv.length+10; i++)
}
return dataPoints;
}
回答1:
Don't use Math.min(). Just test if price is lower than lowestv. If it is, save the price in lowestv and save the row in another variable.
function getDataPointsFromCSV(csv) {
csvLines = csv.split(/[\r\n]+/);
let lowestv = Infinity;
let lowestrow;
csvLines.forEach(line => {
row = line.split(',');
price = row[4];
if (price < lowestv) {
lowestv = price;
lowestrow = row;
}
})
return lowestrow;
}
来源:https://stackoverflow.com/questions/59909191/find-math-min-row-value