And "brightest" and "darkest" means what? Luminance? Predominant color? Percentage of a specific color? You see, already therein lies a can of worms waiting to be opened up. Likewise, reordering them with time-remapping would probably be extremely slow since you need to calculate the value for every frame and thge longer the layer, the more time it takes. It's not impossible, but it's going to be a major pain and requires much more detailed explanations.
For now, I'm just taking the RGB channels and averaging them to get a single value, which roughly corresponds to luminance. That part, I've figured out how to do. It's the re-ordering part that's got me totally stumped!
How are you getting the RGB values, sampleImage()? At each frame, your expression would have to take samples at every frame of the comp (huge cpu killer), then sort the results and the corresponding frame numbers, then, using the current frame number as an index into the array, get the appropriate frame number to display. Theoretically possible, but I doubt performance would be acceptable unless your comp is really short.