查找Math.min行值 [英] find Math.min row value

查看:46
本文介绍了查找Math.min行值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找到Math.min的行值,但是即使搜索了几天,我也不知道如何找到它.
有人可以告诉我如何解决此问题吗?

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

推荐答案

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

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

这篇关于查找Math.min行值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆