I've created athe following function to add the cloud+shadow+snow percentage for a particular region as a new image property so you can filter the image collection based on that new property. The 'region' in the function refers to your area of interest or aoi.
// Function to add the cloud, shadow and snow percentge as a new property for each image. It uses 'QA_PIXEL' band
function add_cloudCover(img){
// Bit 3 - Cloud
// Bit 4 - Cloud Shadow
// Bit 5 - Snow
var cloudsBitMask = 1 << 3;
var cloudShadowBitMask = 1 << 4;
var snowBitMask = 1 << 5;
var qa = img.select('QA_PIXEL').clip(region);
var unmasked = qa.gt(0)
var unmasked_area = unmasked.multiply(ee.Image.pixelArea());
var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
.and(qa.bitwiseAnd(cloudsBitMask).eq(0)
.and(qa.bitwiseAnd(snowBitMask).eq(0)));
var masked_area = mask.multiply(ee.Image.pixelArea());
var u_area = unmasked_area.reduceRegion({
reducer: ee.Reducer.sum(),
geometry: region.geometry(),
scale: 30,
maxPixels: 1e10
});
var area = masked_area.reduceRegion({
reducer: ee.Reducer.sum(),
geometry: region.geometry(),
scale: 30,
maxPixels: 1e10
});
var landCover = ee.Number(area.get('QA_PIXEL')).multiply(100).divide(ee.Number(u_area.get('QA_PIXEL')));
var cloudCover = ee.Number(100).subtract(landCover).round();
return img.set('CLOUD_SHADOW_SNOW_COVER_REGION', cloudCover);
}
function add_cloudCover(img){ // Bit 3 - Cloud // Bit 4 - Cloud Shadow // Bit 5 - Snow var imagen = img var cloudsBitMask = 1 << 3; var cloudShadowBitMask = 1 << 4; var snowBitMask = 1 << 5; var qa = img.select('QA_PIXEL').clip(region); var unmasked = qa.gt(0) var unmasked_area = unmasked.multiply(ee.Image.pixelArea()); var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0) .and(qa.bitwiseAnd(cloudsBitMask).eq(0) .and(qa.bitwiseAnd(snowBitMask).eq(0))); var masked_area = mask.multiply(ee.Image.pixelArea()); var u_area = unmasked_area.reduceRegion({ reducer: ee.Reducer.sum(), geometry: region.geometry(), scale: 30, maxPixels: 1e10 }); var area = masked_area.reduceRegion({ reducer: ee.Reducer.sum(), geometry: region.geometry(), scale: 30, maxPixels: 1e10 }); var landCover = ee.Number(area.get('QA_PIXEL')).multiply(100).divide(ee.Number(u_area.get('QA_PIXEL'))); var cloudCover = ee.Number(100).subtract(landCover).round(); return img.set('CLOUD_SHADOW_SNOW_COVER_REGION', cloudCover); }