相同的值數組我有一個數組:集團在ActionScript
var exArr:Array = [5,6,10,6,5,11,7,9,12,8,8,13,7,9,14];
我想數組:
var resultArr:Array = [5,6,7,8,9,10,11,12,13,14];
相同的值數組我有一個數組:集團在ActionScript
var exArr:Array = [5,6,10,6,5,11,7,9,12,8,8,13,7,9,14];
我想數組:
var resultArr:Array = [5,6,7,8,9,10,11,12,13,14];
這可能會使用全給你。
var a:Array = [5,6,10,6,5,11,7,9,12,8,8,13,7,9,14];
a.sort();
var i:int = 0;
while(i < a.length) {
while(i < a.length+1 && a[i] == a[i+1]) {
a.splice(i, 1);
}
i++;
}
其他,see here
試試這個:
var exArr:Array = [5,6,10,6,5,11,7,9,12,8,8,13,7,9,14];
function group(subject:Array):Array
{
var base:Array = subject.slice().sort(Array.NUMERIC);
var prev:Number = base[0];
for(var i:int = 1; i < base.length; i++)
{
if(base[i] === prev)
{
base.splice(i, 1);
i--;
}
prev = base[i];
}
return base;
}
trace(group(exArr));
這應該是一個被接受的答案 - 嵌套循環的單循環 – 2013-03-12 08:49:22
這給出結果'10,11,12,13,14,5,6,7,8,9'。 – Marty 2013-03-12 06:48:33
非常感謝你 – 2013-03-12 07:06:06