SOURCE

function randomNum(min, max) {
	return Math.floor(Math.random() * (max - min)) + min; // You can remove the Math.floor if you don't want it to be an integer
}

let answer = [50, 10, 10, 60, 10, 50]
let score = answer;
let featureIdxscore = answer;
for (const idx in answer) {
  score[idx] = 50 - Math.abs(50 - answer[idx])
}
let scoreMin = score;
scoreMin.sort();
tmpIdx = 3
while(tmpIdx < 6 && scoreMin[tmpIdx - 1] == scoreMin[tmpIdx]){
    tmpIdx = tmpIdx + 1;
}

featureIdx = []
for (const idx in score) {
  if(score[idx] <= scoreMin[tmpIdx]){
      if(answer[idx] < 50){
          featureIdx.push(idx * 2)
      } else if (answer[idx] > 50){
          featureIdx.push(idx * 2 + 1)
      } else{
          featureIdx.push(idx * 2 + randomNum(0, 1));
      }
      
  }
}
console.log(score)
console.log(kthsmallestelement(score, 6, 6))
console.log(featureIdx)
console 命令行工具 X clear

                    
>
console