Voor een spelletje in AS3 heb ik een functie die het aantal unieke karakters in een string telt:
De functie returned altijd 0, ik kan niet vinden waar de fout zit
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| function countUniqueChars(woord:String){
var counter:int = 0;
var tempArray:Array = new Array();
var tempArray2:Array = new Array();
tempArray = woord.split("",woord.length);
for(i;i<tempArray.lenght;i++){
for(i;i<tempArray2.lenght;i++){
if(tempArray[i] == tempArray2[i]){
counter++
trace(counter);
}else{
tempArray2.push(tempArray[i]);
}
}
}
return tempArray2.length;
} |
De functie returned altijd 0, ik kan niet vinden waar de fout zit