var e = [3, 1, 1, 2, 5, 4, 3, 2]
function sort(e) {
for (var i = 0; i < e.length - 1; i++) {
for (var j = 0; j < e.length - 1 - i; j++) {
if (e[j] > e[j + 1]) {
var swap = e[j];
e[j] = e[j + 1];
e[j + 1] = swap;
}
}
}
}
sort(e);
console.log(e)
数组去重
var arr = [1, 3, 4, 5, 6, 6, 2, 3];
function a(arr) {
var tmpArr = [];
for (i in arr) {
if (tmpArr.join(',').indexOf(arr[i]) == -1) {
tmpArr.push(arr[i]);
}
}
return tmpArr
}
console.log(a(arr));
var arr = [1, 3, 4, 5, 6, 6, 2, 3];
function q(arr) {
arr.sort();
var hash = [arr[0]];
for (var i = 1; i < arr.length; i++) {
if (arr[i] != hash[hash.length - 1]) {
hash.push(arr[i]);
}
}
return hash;
}
console.log(q(arr))