其他分享
首页 > 其他分享> > 获取最大最小数值以及下标

获取最大最小数值以及下标

作者:互联网

/**
 * 获取数组最大值下标
 */
const findMaxIndex = (numberList) => {
  let maxValue = parseFloat(numberList[0]);
  let minValue = parseFloat(numberList[0]);
  let maxIndex = 0;
  let minIndex = 0;
  for (let i = 0; i < numberList.length; i++) {
    let current = parseFloat(numberList[i]);
    if (current > maxValue) {
      maxValue = current;
      maxIndex = i;
    } else if (current < minValue) {
      minValue = current;
      minIndex = i;
    }
  }
  return maxIndex
}

 

标签:下标,最小,数值,minValue,current,parseFloat,let,numberList,maxValue
来源: https://www.cnblogs.com/Nyan-Workflow-FC/p/16477035.html