I am looking to make an image collection that holds the 95th percentile of NDVI for each year from 1985 - 2011 for the Landsat 5 record. I am able to create the 95th percentile composites, but I would like to avoid copy and pasting to change the year. This is what a single year would look like. How do I easily loop/map over each year to create an image collection that holds finalmask_1985, finalmask_1986, finalmask_1987.... and so on?
//////////////////////////////////////////////////////////////////////////
//1985
//////////////////////////////////////////////////////////////////////////
//Load Landsat 5 image collection
var collection_1985= ee.ImageCollection('LANDSAT/LT05/C01/T1_TOA')
.filterDate('1985-01-01','1985-12-31')
.map(addQualityBand);
//Isolate NDVI and time band
var only_NDVI_1985 = collection_1985.select('nd','system:time_start');
//Create image counts mask
var count_1985 = only_NDVI_1985.select('nd').reduce(ee.Reducer.count());
var countmask_1985 = count_1985.select('nd_count').gte(10);
//Make 95th percentile NDVI composite
var ninety_five_percent_1985 = only_NDVI_1985.reduce(ee.Reducer.percentile([95]));
//Create NDVI <.1 mask
var mask95_1985 = ninety_five_percent_1985.select('nd_p95').gte(0.1);
//Apply masks
var lte95_1985 = ninety_five_percent_1985.updateMask(mask95_1985);
var finalmask_1985 = lte95_1985.updateMask(countmask_1985);
Here is the link to the full script: https://code.earthengine.google.com/3674fa123d228d3a5a17b0fbcdeb3f60