Adobe Flex: how to compare arrays
At some point I needed to compare two arrays: do they consist of the identical data? And I realized that there is no built-in function for this. I wrote the simple function which correctly compares two arrays and returns a boolean if arrays are the same:
/** Compare arrays */ private function matchArrays(a1:Array, a2:Array):Boolean { var len1:int = a1.length; if (len1 != a2.length) return false; for( var i:int = 0; i<len1; i++ ) { if (a1[i] != a2[i]) return false; } return true; }Funny thing about web development is that writing service functions like this we are reinventing a wheel again and again infinite number of times. I found similar function later in Adobe corelib library in com.adobe.utils.ArrayUtil :)
Comments
Post a Comment