csv 查找数学最小行值

7lrncoxx  于 2023-09-28  发布在  其他
关注(0)|答案(1)|浏览(82)

我想找到Math.min的行值,但我不知道如何找到它,即使我已经谷歌了几天。
有人能告诉我如何解决这个问题吗?

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]=(column5)                 
                    price = points[4]
<!-- find the row number which store lowest value in a column               
                    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;
        }
pvcm50d1

pvcm50d11#

不要使用Math.min()。只需测试price是否低于lowestv。如果是,将价格保存在lowestv中,并将该行保存在另一个变量中。

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;
}

相关问题