2013-06-19 44 views
-1

需要有从一个数组复制的价值,并得到下面的代码工作很好,但在AS3的ActionScript:从AS3转换的功能,AS2

请某人能转换这个AS3代码AS2?

var array:Array = [1,2,3,4,3]; 

// create a dictionary and go through our array, pulling out the values 
var dict:Dictionary = new Dictionary(); 
var len:int   = array.length; 
for(var i:int = 0; i < len; i++) 
{ 
    var val:int = array[i]; // get the value from the array 
    if(!(val in dict)) // if it's not in our dictionary, create a new array 
     dict[val] = []; 
    dict[val].push(i); // add the index of the value to the array 
} 

// now go through our dictionary, finding the duplications 
for(var key:* in dict) 
{ 
    var indicies:Array = dict[key]; 
    if(indicies.length <= 1) 
     continue; // single value - ignore 
    trace("The value " + key + " is repeated " + indicies.length + " times. Indicies: " + indicies); 
} 
  • 错误代码:

  • 序列=序列1,层=借译1帧= 1,2 LIGNE不可能去充电器拉CLASSE OU L'界面 '词典'。

  • Séquence=Séquence1,layer = Calque 1,frame = 1,ligne 3 Impossible de charger la classe ou l'interface'int'。

  • Séquence=Séquence1,layer = Calque 1,frame = 1,ligne 4 Impossible de charger la classe ou l'interface'int'。

  • Séquence=Séquence1,layer = Calque 1,frame = 1,ligne 6 Impossible de charger la classe ou l'interface'int'。

  • 序列=序列1,层=借译1帧= 1,LIGNE 7 ')' attendu

  • 序列=序列1,层=借译1帧= 1,LIGNE 10 '}' inattendu
+0

是的,错误是在主帖 –

回答

0

如何:

var array:Array = [1,2,3,4,3]; 
var obj:Object = new Object(); 

for(var i:int = 0; i < array.length; i++) 
{ 
    if(obj[ array[i]] === undefined) 
    { 
     obj[ array[ i ]] = i; 
    } 
    else trace("the value " + array[i] + " from location " + obj[ array[ i ]] + " is repeated at location " + i); 
} 

(这只是对代码,我没有在我面前的编译器。)

那你婉结果呢?

+0

谢谢队友,但如何知道数组中的值在哪里重复? –

+0

修改为包含重复位置的参考 – ethrbunny

+0

结果:值3在位置4重复但必须在位置2和4重复 –