标签:func strong str == 数组 indexof logs set color
数组去重:1.
1 var aa=[1,3,5,4,3,3,1,4] 2 function arr(arr) { 3 var result=[] 4 for(var i=0; i<arr.length; i++){ 5 if(result.indexOf(arr[i])==-1){ 6 result.push(arr[i]) 7 } 8 } 9 console.log(result) 10 } 11 arr(aa)
2.
1 let array = Array.from(new Set([1, 1, 1, 2, 3, 2, 4])); 2 console.log(array); 3 // => [1, 2, 3, 4]
冒泡排序:
1 var array = [5, 4, 3, 2, 1]; 2 var temp = 0; 3 for (var i = 0; i < array.length; i++) 4 { 5 for (var j = 0; j < array.length - i; j++) 6 { 7 if (array[j] > array[j + 1]) 8 { 9 temp = array[j + 1]; 10 array[j + 1] = array[j]; 11 array[j] = temp; 12 } 13 } 14 } 15 console.log(array);
标签:func strong str == 数组 indexof logs set color
原文地址:http://www.cnblogs.com/queenw/p/7673824.html