console.log(noRepeat([-2, 1, -3, 4, -1, 2, 1, -5, 4]));
//[4, 2, 1, -1, -2, -3, -5]
console.log(noRepeat([-14, 10, -13, 4, -21, 2, 1, -5, 4]));
//[10, 4, 2, 1, -5, -13, -14, -21]
//数组去重
function noRepeat(arr) {
var arrnew = [];
for (var i = 0; i <arr.length; i++){
if (arrnew.indexOf(arr[i]) == -1) {
arrnew.push(arr[i])
}
}
//从大到小排序,如果改成从小到大排序,“b-a”改成‘a-b’
function compare(a,b) {
return b - a;
}
//数组按从大到小排序
arrnew.sort(compare);
return arrnew;
}