This content has been marked as final. Show 3 replies
You could use Array.sortOn("age",Array.NUMERIC). This should sort the array, and you may check the first entries for their age value. But you would have to go through the whole array agin in the worst case, so it should be better to write a small function that returns an array containing all entries with age==50. Something like the attached (I assume there are objects in the array with an "age" property that has a Number assigned).
Maybe clear enough, but why does it have to be sort? Doesn't really have anything to do with sort does it?
You want a find type of function or some such. Just make a function that does what you want. I'm guessing you don't want to destroy the original array so just step through the original array, compare what you want, put the ones that match in a new array, and return the array.
Depending upon exactly what you are doing you could copy the entire element from the original array or just a reference to its position in the array.
PS: You might want to use Array.sortOn() to make the searching easier.
"Maybe clear enough, but why does it have to be sort? Doesn't really have anything to do with sort does it?"
Not patronising at all is it. If I knew that then I would not be asking.
I’ve been able to sort it out so thanks for everyone’s help with this one.