Q: Including conditional operation depending on number of images? I want to do certain operations depending on the number of images in a filtered collection. I am working within a loop, so I need the condition to jump to the next step in the loop given a condition. Here is some code example:
var S2 = ee.ImageCollection("COPERNICUS/S2");
var point = ee.Geometry.Point([2.32,37.25]);

//This is within a function (loop)

// Filtering the image collection in a specific point for a time period
var S2TemporalFiltered = S2.filterDate('2017-04-12','2017-04-25');
var S2SpatialFiltered = S2TemporalFiltered.filterBounds(point);

// Calculating the number of images
var numberImages = S2SpatialFiltered.size()

// Now do something like:
// if (numberImages == 0):
//     Jump to the next iteration step
// else:
//     Stay in the loop function


A: Probably ee.Algorithms.If() is something you are looking for:
var newCollection = ee.ImageCollection(ee.Algorithms.If({condition: S2SpatialFiltered.size(), 
                  trueCase: S2SpatialFiltered.median(),       // do something with the image collection
                  falseCase: S2SpatialFiltered}));            // return the same collection

Note that the GEE does not know what kind of variable will come out of the algorithm.If(), so you will always have to cast it to a certain ee.Object.
