# Filtering data in an Array

Hi all,

I have an array that has 30 date objects. The date objects are indexed in the array from minimum date value to maximum date value. What I would like to do is retrieve only 7 dates from the array. Out of the 7, the first one should be the minDate and the last should be the maxDate, with 5 dates in the middle. The 7 numbers should increment evenly from the minDate to the maxDate. How would I accomplish this? Hope I was clear.

Thanks,
Tonih
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

IT ExpertCommented:
Here is the first and last part

Author Commented:
Thanks mplugjan!

is it possible to show an entire solution? I'm really am not getting this. Would you know how to do this with actionscript?

thanks

IT ExpertCommented:
1. I do not do actionscript
2. You need some kind of math to find some kind of median values

The link I gave you shows how to sort a date array
IT ExpertCommented:
Okay - seems you found a solution elsewhere. Please share when you have a complete solution.
Thanks
Author Commented:
Sorry for very late reply. I found a solution. If there is a better one, please suggest. Thanks.

var midpt = Math.ceil((my_array.length-2)/2);
var apt = Math.floor(midpt/3);
var off = (mid%3);

trace(my_array[0]);
trace(my_array[(off>3) ? apt+1 : apt]);
trace(my_array[(off>1) ? midpt-apt : midpt-apt-1]);
trace(my_array[midpt]);
trace(my_array[(off>0) ? midpt+apt : midpt+apt+1]);
trace(my_array[(off>2) ? my_array.length-1-apt : my_array.length-1-apt-1]);
trace(my_array[my_array.length-1]);

Experts Exchange Solution brought to you by