<script type="text/javascript">
var a = {
aa:function(arr){
var arr2 = [];
for(var i = 0;i<arr.length;i++){
if(arr2.indexOf(arr[i]) == '-1'){
arr2.push(arr[i]);
}
}
console.log(arr2)
},
bb:function(arr){
arr.sort();
var re=[arr[0]];
for(var i = 1; i < arr.length; i++){
//将当前的一个元素与无重复集合的最后一个元素依次对比,如果不相等,那么push到无重复集合
if( arr[i] !== re[re.length-1]){
re.push(arr[i]);
}
}
console.log(re)
},
cc:function(arr){
var r = [];
for(var i = 0, l = arr.length; i < l; i++) {
for(var j = i + 1; j < l; j++){
if (arr[i] === arr[j]){
j = ++i;
}
}
r.push(arr[i]);
}
console.log(r)
}
}
a.aa([1,1,2,3,4,5,5,2,1,4,3,6])
a.bb([1,1,2,3,4,5,5,2,1,4,3,6])
a.cc([6,2,3,7,2,3,1,2,3,3,5,2,2,1,1])
//闭包循环依次输出1-5
for(var i = 1;i<=5;i++){
(function(i){
setTimeout(function(){
console.log(i)
},i*1000)
})(i)
}
</script>