SHARE
TWEET

Untitled

a guest Apr 26th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // 定义一个函数 该函数可以获取数组中最小的值的下标
  2. function getMinIdx(arr) {
  3.     // 返回最小的值的下标
  4.     // 默认最小的值下标
  5.     var idx = 0;
  6.     // 默认最小的值
  7.     var val = arr[idx];
  8.     // 循环比较其他项
  9.     for (var i = 1; i < arr.length; i++) {
  10.         // 如果最小的值val 还比当前的项大 说明不是最小
  11.         if (val > arr[i]) {
  12.             val = arr[i];
  13.             idx = i;
  14.         }
  15.     }
  16.     return idx;
  17. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top