如果不能用列排序,参考一下这个从数组里面直接取。
var vals = [1, 3, 5, 2,6,9,4];
var max1 = maxa(vals);
vals = removeValueFromArray(vals, max1);
var max2 = maxa(vals);
vals = removeValueFromArray(vals, max2);
var max3 = maxa(vals);
var min1 = mina(vals);
vals = removeValueFromArray(vals, min1);
var min2 = mina(vals);
vals = removeValueFromArray(vals, min2);
var min3 = mina(vals)
function removeValueFromArray(vs, v) {
var nvs = new Array();
var first = true;
for(var t = 0; t < vs.length; t++) {
if(vs[t] == v && first) {
first = false;
continue;
}
nvs[nvs.length] = vs[t];
}
return nvs;
} |