Google Earth Engine – Get Image with lowest NDVI from a time period

google-earth-enginemaximumndvi

One of the answers to this question (Google Earth Engine – Get Image with highest max Scene NDVI from a time period) provides code which gives a Sentinel image/date with the highest NDVI for each region (https://code.earthengine.google.com/5165eca22f5dbfc8e114919d9315ab73).

This is half of what I want, but I also want the Sentinel image/date of the lowest NDVI for a region, but am not sure how. I have tried changing

return ee.Feature(meanFeatureCollection.sort('mean').first()

to descending order, but it didn't change the console output.

EDIT: I double checked and the link code doesn't actually do as described, it only prints the NDVI and ID of first Sentinel image in the collection. So I also need the correct script to identify highest AND lowest NDVI images.

Best Answer

In the link here, the code provided as an answer to the question you referred to.
For getting lowest value, you can change max to min

var highestMean = mosaicsWithMean.aggregate_max('mean')

to

var lowestMean = mosaicsWithMean.aggregate_min('mean')