find Math.min row value

守給你的承諾、 提交于 2021-01-29 13:23:55

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!