function isEligible(value,userID) { // .. whatever arbitrary logic .. } const buckets = [ user1: new Set(), user2: new Set(), user3: new Set(), user4: new Set() } const specialValue = 42; const count = ( Object.entries(buckets) .filter(([userID,bucket]) => isEligible(specialValue,userID)) .reduce((counter,[userID,bucket]) => (bucket.add(specialValue),counter+1),0) ); if (count >= 2) { console.log("at least 2 users were eligible for the special value!"); }