数组去重ES5的方法
function unique(){var res = [];var json = {};for(var i = 0; i < this.length; i++){if(!json[this[i]]){res.push(this[i]);json[this[i]] = 1;}}return res;
}
ES6写法
let test=[1,2,3,3,2,1]
[...new Set(test)]
数组快排
var quickSort = function(arr) {if (arr.length <= 1) { return arr; }var pivotIndex = Math.floor(arr.length / 2);var pivot = arr.splice(pivotIndex, 1)[0];var left = [];var right = [];for (var i = 0; i < arr.length; i++){if (arr[i] < pivot) {left.push(arr[i]);} else {right.push(arr[i]);}}return quickSort(left).concat([pivot], quickSort(right));
};