RE: [flexcoders] Array Item Counting
Believe it or not, some of us have never had a single "cs course"! Tracy From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Seth Caldwell Sent: Wednesday, January 23, 2008 5:41 PM To: flexcoders@yahoogroups.com Subject: RE: [flexcoders] Array Item Counting Not to be harsh, but this sounds like something my first cs course in college would have had as an assignment or problem in a homework set. This has nothing to do with flex... var A:Array = [15,15,35,35,35,35, 35,55,55,75,95,105,115,115,115]; var B:Array = new Array(); Var maxrun:Number=0; for each(var n:Number in A) { if(!B[n]) B[n]=1; else B[n]++; if(B[n]>maxrun) maxrun=B[n]; } From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of jmfillman Sent: Wednesday, January 23, 2008 2:26 PM To: flexcoders@yahoogroups.com 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); } }
Re: [flexcoders] Array Item Counting
- Original Message - From: "Paul Andrews" <[EMAIL PROTECTED]> To: Sent: Wednesday, January 23, 2008 10:47 PM Subject: Re: [flexcoders] Array Item Counting > - Original Message - > From: "jmfillman" <[EMAIL PROTECTED]> > To: > 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; idxcurr = myArr[idx]; > if (curr == prev) { > curRun++; > } else { > if (curRun > longest) { > longest = curRun; > } > curRun =1; > prev=curr; > } > } > trace(longest); LOL it's late: var myArr:Array = [15,15,35,35,35,35,35,55,55,75,95,105,115,115,115]; var longest:Number=1; var curRun:Number=1; var curr:Number; var prev:Number = myArr[0]; for (var idx:Number=1; idx longest) { longest = curRun; } } else { curRun =1; prev=curr; } } trace(longest);
RE: [flexcoders] Array Item Counting
> 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: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Paul Andrews Sent: Wednesday, January 23, 2008 2:48 PM To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] Array Item Counting - Original Message - From: "jmfillman" <[EMAIL PROTECTED] <mailto:jmfillman%40verizon.net> > To: 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 longest) { longest = curRun; } curRun =1; prev=curr; } } trace(longest);
Re: [flexcoders] Array Item Counting
- Original Message - From: "jmfillman" <[EMAIL PROTECTED]> To: 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 longest) { longest = curRun; } curRun =1; prev=curr; } } trace(longest);
RE: [flexcoders] Array Item Counting
Not to be harsh, but this sounds like something my first cs course in college would have had as an assignment or problem in a homework set. This has nothing to do with flex. var A:Array = [15,15,35,35,35,35, 35,55,55,75,95,105,115,115,115]; var B:Array = new Array(); Var maxrun:Number=0; for each(var n:Number in A) { if(!B[n]) B[n]=1; else B[n]++; if(B[n]>maxrun) maxrun=B[n]; } From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of jmfillman Sent: Wednesday, January 23, 2008 2:26 PM To: flexcoders@yahoogroups.com 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); } }