Here's a snippet to get you started, based on code in this blog post:
var temporalCollection = function(collection, start, count, interval, units) {
// Create a sequence of numbers, one for each time interval.
var sequence = ee.List.sequence(0, ee.Number(count).subtract(1));
var originalStartDate = ee.Date(start);
return ee.ImageCollection(sequence.map(function(i) {
// Get the start date of the current sequence.
var startDate = originalStartDate.advance(ee.Number(interval).multiply(i), units);
// Get the end date of the current sequence.
var endDate = originalStartDate.advance(
ee.Number(interval).multiply(ee.Number(i).add(1)), units);
return collection.filterDate(startDate, endDate).median()
.set('system:time_start', startDate.millis())
.set('system:time_end', endDate.millis());
}));
};
var landsat8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA');
var result = temporalCollection(landsat8, '2016-01-01', 12, 32, 'day');
var first = ee.Image(result.first());
Map.addLayer(first, {bands: ['B4', 'B3', 'B2'], min: 0, max: 0.3}, 'first');
Note that another variant of this is described in this answer.