It's not necessary. I was doing it to make it easier to validate my count. I was also playing with splice.
--- In [email protected], "Gordon Smith" <[EMAIL PROTECTED]> wrote: > > > The array is then sorted to group identical values together. > > If all you're doing is counting how many times each number appears, and > then determining which one appears most frequently, why are you > bothering to sort the Array? > > Gordon Smith > Adobe Flex SDK Team > > ________________________________ > > From: [email protected] [mailto:[EMAIL PROTECTED] On > Behalf Of Paul Andrews > Sent: Wednesday, January 23, 2008 2:48 PM > To: [email protected] > Subject: Re: [flexcoders] Array Item Counting > > > > ----- Original Message ----- > From: "jmfillman" <[EMAIL PROTECTED] > <mailto:jmfillman%40verizon.net> > > To: <[email protected] <mailto:flexcoders% 40yahoogroups.com> > > Sent: Wednesday, January 23, 2008 10:25 PM > Subject: [flexcoders] Array Item Counting > > >I have an array with several dynamically populated numbers. The array > > is then sorted to group identical values together. > > > > Let's say my array contains the following:[15,15,35,35,35,35, > > 35,55,55,75,95,105,115,115,115] > > > > What I need to do is get a count of each number, and determine the > > highest frequency, in the above example, the number 35 is listed 4 > > times, so I would need to set a variable = 4. I've been playing around > > > with a for loop. Since I have 168 potential matches (15, 35, 55, 75, > > 95, all the way to 2875) incrementing by 20, that's a bit excessive > for > > a bunch of if statements. It seems like a nested for loop could do > > this, but I can't figure it out. Maybe there's an even better way I > > haven't considered. > > > > for (var rowCount:int=0;rowCount < arrayRows.length;rowCount++){ > > var my15:int; > > if (arrayRows[rowCount].row == 15){ > > my15 = my15+1; > > trace (my15); > > } > > } > > var myArr:Array = [15,15,35,35,35,35,35,55,55,75,95,105,115,115,115]; > var longest:Number=0; > var curRun:Number=1; > var curr:Number; > var prev:Number = myArr[0]-1; > > for (var idx:Number=0; idx<myArr.length; idx++){ > curr = myArr[idx]; > if (curr == prev) { > curRun++; > } else { > if (curRun > longest) { > longest = curRun; > } > curRun =1; > prev=curr; > } > } > trace(longest); >

