标签:
function removeRepeat(arr) { var arr2 = [] ,obj = {}; for (var i = 0; i<arr.length; i++) { var num = arr[i]; //先把arr的第[i]num if( !obj[num] ){ //如果上面有个true,那么就不要push进数组,否则就push进数组 arr2.push(num); obj[num] = true; //不要忘记push到数组以后把obj上的属性设置为true,那么下次有一样的属性就不会进来了 } } console.log(arr2); } removeRepeat([1,2,5,2,1,5,5,2,1,1,5,2,2,5,1]);
var quickSort = function(arr) { if (arr.length <= 1) { return arr; } else { //split for center var pivotIndex = Math.floor(arr.lenght / 2); //get center value 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]); } } } //call me loop return quickSort(left).concat([pivot], quickSort(right)); };
标签:
原文地址:http://www.cnblogs.com/web-alibaba/p/4836842.html