Snippets Collections
[
    {
        "$match": {
            "authorization": {
                "$ne": null
            }
        }
    },
    {
        "$match": {
            "email": {
                "$not": {
                    "$regularExpression": {
                        "pattern": "deleted",
                        "options": ""
                    }
                }
            }
        }
    },
 
    {
        "$lookup": {
            "from": "participant",
            "localField": "email",
            "foreignField": "email",
            "as": "userParticipant"
        }
    },
    {
        "$match": {}
    },
    {
        "$lookup": {
            "from": "masterSlot",
            "localField": "userParticipant._id",
            "foreignField": "navigatorId",
            "as": "slots"
        }
    },
    {
        "$lookup": {
            "from": "userCoachMapping",
            "localField": "userParticipant._id",
            "foreignField": "coachID",
            "as": "userCoachMapping"
        }
    },
    {
        "$project": {
        
            "isCoachActive": {
                "$arrayElemAt": [
                    "$userParticipant.active",
                    0
                ]
            },
        
            "email": {
                "$arrayElemAt": [
                    "$userParticipant.email",
                    0
                ]
            },
            "firstName": {
                "$arrayElemAt": [
                    "$userParticipant.firstName",
                    0
                ]
            },
            "coachProfileDescription": {
                "$arrayElemAt": [
                    "$userParticipant.coachProfileDescription",
                    0
                ]
            },
    
            "middleName": {
                "$arrayElemAt": [
                    "$userParticipant.middleName",
                    0
                ]
            },
            "lastName": {
                "$arrayElemAt": [
                    "$userParticipant.lastName",
                    0
                ]
            },
            "partnerShortCode": {
                "$arrayElemAt": [
                    "$userParticipant.partnerShortCode",
                    0
                ]
            },
    
            "role": {
                "$arrayElemAt": [
                    "$userParticipant.role",
                    0
                ]
            },
            "templateName": "$authorization.name",
            "servicePartnerShortCode": "$servicePartnerShortCode",
            "userVisibility": "$userVisibility",
    
            "Total Users": {
                "$size": {
                    "$filter": {
                        "input": "$userCoachMapping",
                        "as": "coach",
                        "cond": { "$eq": ["$$coach.userStatus", "ACTIVE"] }
                    }
                }
            }
            _id:0
        }
    },
    {
        $match:{
            "Total Users": { "$gt": 0 }
        }
    }
]
[
    {
        "$match": {
            "startDate": {
                "$gte": {
                    "$date": "2018-03-12T03:26:21.997Z"
                },
                "$lte": {
                    "$date": "2024-03-10T04:50:35Z"
                }
            }
        }
    },
    {
        "$lookup": {
            "from": "participant",
            "localField": "userId",
            "foreignField": "_id",
            "as": "participantData"
        }
    },
    {
        "$unwind": "$participantData"
    },
    {
        "$match": {
            "participantData.email": {
                "$regularExpression": {
                    "pattern": "@jiva.user",
                    "options": ""
                }
            }
        }
    },
    {
        "$match": {
            "participantData.userStatus": {
                "$ne": "TEST"
            }
        }
    },
    {
        "$match": {
            "$and": [
                {
                    "participantData.email": {
                        "$not": {
                            "$regularExpression": {
                                "pattern": "deleted",
                                "options": ""
                            }
                        }
                    }
                },
                {
                    "participantData.email": {
                        "$not": {
                            "$regularExpression": {
                                "pattern": "@smit\\.fit$",
                                "options": ""
                            }
                        }
                    }
                }
            ]
        }
    },
    {
        "$lookup": {
            "from": "participantBaselineAndFollowupData",
            "localField": "userId",
            "foreignField": "participantId",
            "as": "baselineData"
        }
    },
    {
        "$unwind": "$baselineData"
    },
    {
        "$lookup": {
            "from": "blood_glucose",
            "localField": "userId",
            "foreignField": "participantId",
            "as": "glucoseData"
        }
    },
    {
        "$unwind": "$glucoseData\", \"preserveNullAndEmptyArrays\" : true}"
    },
    {
        "$project": {
            "subscriptionId": "$_id",
            "baselineId": "$baselineData._id",
            "userId": 1,
            "startDate": 1,
            "programStartDate": "$baselineData.programStartDate",
            "planCode1": "$subscriptionPlan.programCode",
            "journeyStatus": "$journeyTrackerObject.status",
            "planCode2": "$baselineData.programCode",
            "followUps": "$baselineData.followUps",
            "glucoseData": 1
        }
    },
    {
        "$match": {
            "$and": [
                {
                    "$expr": {
                        "$and": [
                            {
                                "$eq": [
                                    "$planCode1",
                                    "$planCode2"
                                ]
                            },
                            {
                                "$eq": [
                                    "$startDate",
                                    "$programStartDate"
                                ]
                            }
                        ]
                    }
                }
            ]
        }
    },
    {
        "$group": {
            "_id": {
                "userId": "$userId",
                "startDate": "$startDate",
                "planCode1": "$planCode1"
            },
            "userId": {
                "$last": "$userId"
            },
            "baselineId": {
                "$last": "$baselineId"
            },
            "startDate": {
                "$last": "$startDate"
            },
            "programStartDate": {
                "$last": "$programStartDate"
            },
            "subscriptionId": {
                "$last": "$subscriptionId"
            },
            "journeyStatus": {
                "$last": "$journeyStatus"
            },
            "followUps": {
                "$last": "$followUps"
            },
            "glucoseData": {
                "$push": "$glucoseData"
            }
        }
    },
    {
        "$project": {
            "userId": 1,
            "baselineId": 1,
            "startDate": 1,
            "programStartDate": 1,
            "subscriptionId": 1,
            "journeyStatus": 1,
            "followUps": 1,
            "field": {
                "$add": [
                    "$_id.startDate",
                    {
                        "$multiply": [
                            14,
                            24,
                            60,
                            60,
                            1000
                        ]
                    }
                ]
            },
            "glucoseData": {
                "$filter": {
                    "input": "$glucoseData",
                    "as": "glucose",
                    "cond": {
                        "$and": [
                            {
                                "$lt": [
                                    "$$glucose.date",
                                    {
                                        "$add": [
                                            "$_id.startDate",
                                            {
                                                "$multiply": [
                                                    14,
                                                    24,
                                                    60,
                                                    60,
                                                    1000
                                                ]
                                            }
                                        ]
                                    }
                                ]
                            },
                            {
                                "$gte": [
                                    "$$glucose.date",
                                    "$_id.startDate"
                                ]
                            }
                        ]
                    }
                }
            }
        }
    },
    {
        "$project": {
            "userId": 1,
            "baselineId": 1,
            "startDate": 1,
            "programStartDate": 1,
            "subscriptionId": 1,
            "journeyStatus": 1,
            "followUps": 1,
            "glucoseData": {
                "$map": {
                    "input": "$glucoseData",
                    "as": "obj",
                    "in": {
                        "participantId": "$$obj.participantId",
                        "reading": "$$obj.reading",
                        "date": "$$obj.date"
                    }
                }
            }
        }
    }
]
 const countries = [...new Set(cities)].map(elem => (
  {
    country: elem.country,
    emoji: elem.emoji
  } 
));
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.TreeMap;
import java.util.Random;
public class Main {
  public static void main(String[] args) {
    List<Integer> myInts = new ArrayList<>();
    Random random = new Random();

    for(int i =0; i < 20; i++) {
      myInts.add(random.nextInt(5));
    }

    Map<Integer, Integer> intCount = countNumbers(myInts);
    for(Map.Entry<Integer, Integer> entry: intCount.entrySet()) {
      System.out.println("Integer: "+ entry.getKey()+" appears: "+ entry.getValue());
    }
  }

  public static Map<Integer, Integer> countNumbers(List<Integer> list) {
    Map<Integer, Integer> intCount = new TreeMap<>();
    for(Integer i: list){
      Integer currentCount = intCount.get(i);
      if(currentCount!=null){
        int newCount = currentCount+1;
        intCount.put(i, newCount);}
      else{intCount.put(i, 1);}
    }
    return intCount;
  }

}

/*
Output:
Integer: 0 appears: 3
Integer: 1 appears: 2
Integer: 2 appears: 8
Integer: 3 appears: 1
Integer: 4 appears: 6
//Map defines a generic interface for an object that holds key-value pairs as elements. The key is used to retrieve (like the index in an array or List) some value. A key must be unique and map to exactly one value.
//The HashMap defines no specific ordering for the keys and is the most optimized implementation for retrieving values.
//The LinkedHashMap keeps the keys in insertion order and is slightly less optimal than the HashMap.
//The TreeMap keeps keys in their natural order (or some custom order defined using a Comparator). This implementation has a significant performance decrease compared to HashMap and LinkedHashMap but is great when needing to keep keys sorted.
//A Map has the following methods for accessing its elements:
//put(): Sets the value that key maps to. Note that this method replaces the value key mapped to if the key was already present in the Map.
//get(): Gets, but does not remove, the value the provided key argument points to if it exists. This method returns null if the key is not in the Map.

Map<String, String> myMap = new HashMap<>();
 
myMap.put("Hello", "World") // { "Hello" -> "World" }
myMap.put("Name", "John") //   { "Hello" -> "World" }, { "Name" -> "John" }
 
String result = myMap.get("Hello") // returns "World" 
String noResult = myMap.get("Jack") // return `null`

// Given a map, `myMap`, with the following key-value pairs { "Hello" -> "World" }, { "Name" -> "John"}
for (Map.Entry<String, String> pair: myMap.entrySet()){
  System.out.println("key: "+pair.getKey()+", value: "+pair.getValue());
}
// OUTPUT TERMINAL:
// key: Name, value: John
// key: Hello, value: World


//get list of buttons and make sure there are no duplicates

function displayButtons(){
    const companies = products.reduce((total, item) => {
       total.push(item.company)
       total = [...new Set(total)]
       return total
    },['All'])
 
    const buttons = companies.map((item) => {
       return `<button class="company-btn">${item}</button>`
    }).join('')
 
    buttonsContainer.innerHTML = buttons
 
 }


 // or we could do this...
 const someBtns = ['all',...new Set(products.map((product) => product.company)),];  
  console.log(someBtns)
const persons = [
  {firstname : "Malcom", lastname: "Reynolds"},
  {firstname : "Kaylee", lastname: "Frye"},
  {firstname : "Jayne", lastname: "Cobb"}
];

persons.map(getFullName);

function getFullName(item) {
  return [item.firstname,item.lastname].join(" ");
}
import React from 'react';

const people = [
  {
    name: 'James',
    age: 31,
  },
  {
    name: 'John',
    age: 45,
  },
  {
    name: 'Paul',
    age: 65,
  },
  {
    name: 'Ringo',
    age: 49,
  },
  {
    name: 'George',
    age: 34,
  }
];

function App() {
  return (
    <div>
      {people.filter(person => person.age < 60).map(filteredPerson => (
        <li>
          {filteredPerson.name}
        </li>
      ))}
    </div>
  );
}

export default App;
import React from 'react';

const names = ['James', 'John', 'Paul', 'Ringo', 'George'];

function App() {
  return (
    <div>
      {names.filter(name => name.includes('J')).map(filteredName => (
        <li>
          {filteredName}
        </li>
      ))}
    </div>
  );
}

export default App;
const myObject= {
  'Age': '25',
  'Gender': 'Male',
  'Nationality': 'Australian'
};

const myMap = new Map(Object.entries(myObject)); //object to map
const anotherObject = Object.fromEntries(myMap) // map to object
star

Thu Apr 25 2024 04:12:30 GMT+0000 (Coordinated Universal Time) http://34.74.16.180:3000/question#eyJkYXRhc2V0X3F1ZXJ5Ijp7InR5cGUiOiJuYXRpdmUiLCJuYXRpdmUiOnsiY29sbGVjdGlvbiI6InVzZXJzIiwicXVlcnkiOiJbXHJcbiAgICB7XHJcbiAgICAgICAgXCIkbWF0Y2hcIjoge1xyXG4gICAgICAgICAgICBcImF1dGhvcml6YXRpb25cIjoge1xyXG4gICAgICAgICAgICAgICAgXCIkbmVcIjogbnVsbFxyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfVxyXG4gICAgfSxcclxuICAgIHtcclxuICAgICAgICBcIiRtYXRjaFwiOiB7XHJcbiAgICAgICAgICAgIFwiZW1haWxcIjoge1xyXG4gICAgICAgICAgICAgICAgXCIkbm90XCI6IHtcclxuICAgICAgICAgICAgICAgICAgICBcIiRyZWd1bGFyRXhwcmVzc2lvblwiOiB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIFwicGF0dGVyblwiOiBcImRlbGV0ZWRcIixcclxuICAgICAgICAgICAgICAgICAgICAgICAgXCJvcHRpb25zXCI6IFwiXCJcclxuICAgICAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgICAgICB9XHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICB9XHJcbiAgICB9LFxyXG4gXHJcbiAgICB7XHJcbiAgICAgICAgXCIkbG9va3VwXCI6IHtcclxuICAgICAgICAgICAgXCJmcm9tXCI6IFwicGFydGljaXBhbnRcIixcclxuICAgICAgICAgICAgXCJsb2NhbEZpZWxkXCI6IFwiZW1haWxcIixcclxuICAgICAgICAgICAgXCJmb3JlaWduRmllbGRcIjogXCJlbWFpbFwiLFxyXG4gICAgICAgICAgICBcImFzXCI6IFwidXNlclBhcnRpY2lwYW50XCJcclxuICAgICAgICB9XHJcbiAgICB9LFxyXG4gICAge1xyXG4gICAgICAgIFwiJG1hdGNoXCI6IHt9XHJcbiAgICB9LFxyXG4gICAge1xyXG4gICAgICAgIFwiJGxvb2t1cFwiOiB7XHJcbiAgICAgICAgICAgIFwiZnJvbVwiOiBcIm1hc3RlclNsb3RcIixcclxuICAgICAgICAgICAgXCJsb2NhbEZpZWxkXCI6IFwidXNlclBhcnRpY2lwYW50Ll9pZFwiLFxyXG4gICAgICAgICAgICBcImZvcmVpZ25GaWVsZFwiOiBcIm5hdmlnYXRvcklkXCIsXHJcbiAgICAgICAgICAgIFwiYXNcIjogXCJzbG90c1wiXHJcbiAgICAgICAgfVxyXG4gICAgfSxcclxuICAgIHtcclxuICAgICAgICBcIiRsb29rdXBcIjoge1xyXG4gICAgICAgICAgICBcImZyb21cIjogXCJ1c2VyQ29hY2hNYXBwaW5nXCIsXHJcbiAgICAgICAgICAgIFwibG9jYWxGaWVsZFwiOiBcInVzZXJQYXJ0aWNpcGFudC5faWRcIixcclxuICAgICAgICAgICAgXCJmb3JlaWduRmllbGRcIjogXCJjb2FjaElEXCIsXHJcbiAgICAgICAgICAgIFwiYXNcIjogXCJ1c2VyQ29hY2hNYXBwaW5nXCJcclxuICAgICAgICB9XHJcbiAgICB9LFxyXG4gICAge1xyXG4gICAgICAgIFwiJHByb2plY3RcIjoge1xyXG4gICAgICAgIFxyXG4gICAgICAgICAgICBcImlzQ29hY2hBY3RpdmVcIjoge1xyXG4gICAgICAgICAgICAgICAgXCIkYXJyYXlFbGVtQXRcIjogW1xyXG4gICAgICAgICAgICAgICAgICAgIFwiJHVzZXJQYXJ0aWNpcGFudC5hY3RpdmVcIixcclxuICAgICAgICAgICAgICAgICAgICAwXHJcbiAgICAgICAgICAgICAgICBdXHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgXHJcbiAgICAgICAgICAgIFwiZW1haWxcIjoge1xyXG4gICAgICAgICAgICAgICAgXCIkYXJyYXlFbGVtQXRcIjogW1xyXG4gICAgICAgICAgICAgICAgICAgIFwiJHVzZXJQYXJ0aWNpcGFudC5lbWFpbFwiLFxyXG4gICAgICAgICAgICAgICAgICAgIDBcclxuICAgICAgICAgICAgICAgIF1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgXCJmaXJzdE5hbWVcIjoge1xyXG4gICAgICAgICAgICAgICAgXCIkYXJyYXlFbGVtQXRcIjogW1xyXG4gICAgICAgICAgICAgICAgICAgIFwiJHVzZXJQYXJ0aWNpcGFudC5maXJzdE5hbWVcIixcclxuICAgICAgICAgICAgICAgICAgICAwXHJcbiAgICAgICAgICAgICAgICBdXHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIFwiY29hY2hQcm9maWxlRGVzY3JpcHRpb25cIjoge1xyXG4gICAgICAgICAgICAgICAgXCIkYXJyYXlFbGVtQXRcIjogW1xyXG4gICAgICAgICAgICAgICAgICAgIFwiJHVzZXJQYXJ0aWNpcGFudC5jb2FjaFByb2ZpbGVEZXNjcmlwdGlvblwiLFxyXG4gICAgICAgICAgICAgICAgICAgIDBcclxuICAgICAgICAgICAgICAgIF1cclxuICAgICAgICAgICAgfSxcclxuICAgIFxyXG4gICAgICAgICAgICBcIm1pZGRsZU5hbWVcIjoge1xyXG4gICAgICAgICAgICAgICAgXCIkYXJyYXlFbGVtQXRcIjogW1xyXG4gICAgICAgICAgICAgICAgICAgIFwiJHVzZXJQYXJ0aWNpcGFudC5taWRkbGVOYW1lXCIsXHJcbiAgICAgICAgICAgICAgICAgICAgMFxyXG4gICAgICAgICAgICAgICAgXVxyXG4gICAgICAgICAgICB9LFxyXG4gICAgICAgICAgICBcImxhc3ROYW1lXCI6IHtcclxuICAgICAgICAgICAgICAgIFwiJGFycmF5RWxlbUF0XCI6IFtcclxuICAgICAgICAgICAgICAgICAgICBcIiR1c2VyUGFydGljaXBhbnQubGFzdE5hbWVcIixcclxuICAgICAgICAgICAgICAgICAgICAwXHJcbiAgICAgICAgICAgICAgICBdXHJcbiAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgIFwicGFydG5lclNob3J0Q29kZVwiOiB7XHJcbiAgICAgICAgICAgICAgICBcIiRhcnJheUVsZW1BdFwiOiBbXHJcbiAgICAgICAgICAgICAgICAgICAgXCIkdXNlclBhcnRpY2lwYW50LnBhcnRuZXJTaG9ydENvZGVcIixcclxuICAgICAgICAgICAgICAgICAgICAwXHJcbiAgICAgICAgICAgICAgICBdXHJcbiAgICAgICAgICAgIH0sXHJcbiAgICBcclxuICAgICAgICAgICAgXCJyb2xlXCI6IHtcclxuICAgICAgICAgICAgICAgIFwiJGFycmF5RWxlbUF0XCI6IFtcclxuICAgICAgICAgICAgICAgICAgICBcIiR1c2VyUGFydGljaXBhbnQucm9sZVwiLFxyXG4gICAgICAgICAgICAgICAgICAgIDBcclxuICAgICAgICAgICAgICAgIF1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgXCJ0ZW1wbGF0ZU5hbWVcIjogXCIkYXV0aG9yaXphdGlvbi5uYW1lXCIsXHJcbiAgICAgICAgICAgIFwic2VydmljZVBhcnRuZXJTaG9ydENvZGVcIjogXCIkc2VydmljZVBhcnRuZXJTaG9ydENvZGVcIixcclxuICAgICAgICAgICAgXCJ1c2VyVmlzaWJpbGl0eVwiOiBcIiR1c2VyVmlzaWJpbGl0eVwiLFxyXG4gICAgXHJcbiAgICAgICAgICAgIFwiVG90YWwgVXNlcnNcIjoge1xyXG4gICAgICAgICAgICAgICAgXCIkc2l6ZVwiOiB7XHJcbiAgICAgICAgICAgICAgICAgICAgXCIkZmlsdGVyXCI6IHtcclxuICAgICAgICAgICAgICAgICAgICAgICAgXCJpbnB1dFwiOiBcIiR1c2VyQ29hY2hNYXBwaW5nXCIsXHJcbiAgICAgICAgICAgICAgICAgICAgICAgIFwiYXNcIjogXCJjb2FjaFwiLFxyXG4gICAgICAgICAgICAgICAgICAgICAgICBcImNvbmRcIjogeyBcIiRlcVwiOiBbXCIkJGNvYWNoLnVzZXJTdGF0dXNcIiwgXCJBQ1RJVkVcIl0gfVxyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICBfaWQ6MFxyXG4gICAgICAgIH1cclxuICAgIH0sXHJcbiAgICB7XHJcbiAgICAgICAgJG1hdGNoOntcclxuICAgICAgICAgICAgXCJUb3RhbCBVc2Vyc1wiOiB7IFwiJGd0XCI6IDAgfVxyXG4gICAgICAgIH1cclxuICAgIH1cclxuXSIsInRlbXBsYXRlLXRhZ3MiOnt9fSwiZGF0YWJhc2UiOjJ9LCJkaXNwbGF5IjoidGFibGUiLCJ2aXN1YWxpemF0aW9uX3NldHRpbmdzIjp7fX0=

#aggregation #mongodb #map #filter #size
star

Fri Apr 12 2024 03:17:10 GMT+0000 (Coordinated Universal Time)

#aggregation #mongodb #date #map #filter
star

Tue Feb 27 2024 03:03:42 GMT+0000 (Coordinated Universal Time)

#javascript #duplicates #map #newset
star

Sun Dec 25 2022 22:17:51 GMT+0000 (Coordinated Universal Time)

#java #generics #map
star

Sun Dec 25 2022 22:04:31 GMT+0000 (Coordinated Universal Time)

#java #generics #map
star

Mon Dec 19 2022 23:12:50 GMT+0000 (Coordinated Universal Time)

#reduce #array #map #filter
star

Tue Jul 12 2022 05:31:55 GMT+0000 (Coordinated Universal Time) https://www.w3schools.com/jsref/jsref_map.asp

#array #object #map #join
star

Tue Jun 29 2021 09:34:54 GMT+0000 (Coordinated Universal Time) https://upmostly.com/tutorials/react-filter-filtering-arrays-in-react-with-examples

#array #react.js #javascript #react #filter #map
star

Tue Jun 29 2021 09:30:58 GMT+0000 (Coordinated Universal Time)

#array #react.js #javascript #react #filter #map
star

Tue Nov 24 2020 12:48:26 GMT+0000 (Coordinated Universal Time) https://medium.com/javascript-in-plain-english/stop-using-objects-and-arrays-to-store-data-289c3edaaa33

#javascript #object #map

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension