-
1. Re: building arrays and comparing the contents
kglad Feb 28, 2012 9:16 PM (in response to subtlefly72)function matchesF(a1:Array,a2:Array):int{
var n:int=0;
if(a1.length<=a2.length){
var a:Array=a1.slice();
var b:Array=a2.slice();
} else {
a=a2.slice();
b=a1.slice();
for(var i:int=0;i<a.length;i++){
if(b.indexOf(a[i])>-1){
n++;
}
}
return n;
}
-
2. Re: building arrays and comparing the contents
subtlefly72 Feb 28, 2012 9:21 PM (in response to kglad)Hey I found a really stupid way to get around it! Kglad Iw ill definately look at that code because Iw ant it to work, but I wanted to be able to say "you got one right" or you have them right but there is one wrong answer etc,
So I am using indexOf
if I indexOf("value") a value that isnt in the string, it returns -1, so I can check and say
var a:Number=myArray.indexOf("value that doesnt exist");
if (a<0){
trace("this is a wrong answer");
}
is that stupid? should I not do that?
Cheers
-
3. Re: building arrays and comparing the contents
kglad Feb 28, 2012 9:46 PM (in response to subtlefly72)1 person found this helpfulif you want the number of matches between elements in two arrays, use the code i suggested. if you want to know whether a particular element is in an array, you can use less code:
function memberOf(a,e):Boolean{
if(a.indexOf(e)>-1){
return true;
} else {
return false;
}
-
4. Re: building arrays and comparing the contents
subtlefly72 Feb 28, 2012 9:49 PM (in response to kglad)ok thanks for that, I am getting it to work, but it is good to know the proper way to do it, I am sure it will save me errors in the long run, thanks Kglad!
(Any ideas on getting my xml buttons to light up? http://forums.adobe.com/message/4235956#4235956)
-
5. Re: building arrays and comparing the contents
kglad Feb 29, 2012 6:59 AM (in response to subtlefly72)you're welcome.
(ned is already answering your xml button issue and it's not polite to butt-in when someone has started to address an issue.)