15815213711
2024-08-26 67b8b6731811983447e053d4396b3708c14dfe3c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/**
 * 最小连接数
 */
module.exports = function (tasks, conMap={}) {
  if (tasks.length < 2) return tasks[0] || null;
 
  let min = conMap[tasks[0].id];
  let minIndex = 0;
 
  for (let i = 1; i < tasks.length; i++) {
    const con = conMap[tasks[i].id] || 0;
    if (con <= min) {
      min = con;
      minIndex = i;
    }
  }
 
  return tasks[minIndex] || null;
};