10 days composite from Sentinel 2 Images Collection

A monthly composite can be made using the following code, I take example from Sentinel 2 L1C:

``````var geometry = ee.Geometry.Point([109.061, 11.78]);
var col = ee.ImageCollection('COPERNICUS/S2')
.filterBounds(geometry).filterDate('2018-01-01','2019-01-01');
//Monthly Images
var months = ee.List.sequence(1,12);
var years = ee.List.sequence(2018,2018);
// monthly composite
var monthlyImages =  ee.ImageCollection.fromImages(
years.map(function (y) {
return months.map(function(m){
var w = col.select('B1').filter(ee.Filter.calendarRange(y, y, 'year'))
.filter(ee.Filter.calendarRange(m, m, 'month'))
.mean()
//.median()
//.min()
.set('system:time_start',ee.Date.fromYMD(y,m,1));
return w.set('year', y)
.set('month', m)
.set('date', ee.Date.fromYMD(y,m,1))
.set('system:time_start',ee.Date.fromYMD(y,m,1))

});
}).flatten());

print(monthlyImages)
``````

How do I do a decadal composite (every 10 days)?

First make a ten day interval list:

``````// settings for the years to filter on
var interval = 10;
var increment = 'day';
var start = '2018-01-01';
// make a list of start years
var startDate = ee.Date(start);
var increase = secondDate.subtract(startDate.millis());
var list = ee.List.sequence(startDate.millis(), ee.Date('2019-01-01').millis(), increase);
``````

Then map over that list and filter to get images in that daterange:

``````// monthly composite
var tenDaysMeans =  ee.ImageCollection.fromImages(list.map(function(date){