Skip to content

Instantly share code, notes, and snippets.

View hrishi7's full-sized avatar
🏠
Working from home

Hrishikesh Baidya hrishi7

🏠
Working from home
View GitHub Profile
@hrishi7
hrishi7 / splice-object-array.js
Created November 22, 2021 11:45 — forked from scottopolis/splice-object-array.js
Remove object from array of objects in Javascript
// we have an array of objects, we want to remove one object using only the id property
const apps = [{id:34,name:'My App',another:'thing'},{id:37,name:'My New App',another:'things'}];
// get index of object with id of 37
const removeIndex = apps.findIndex( item => item.id === 37 );
// remove object
apps.splice( removeIndex, 1 );
@hrishi7
hrishi7 / Wysa LeetCode Challenge Solution
Created March 17, 2021 17:56
Wysa LeetCode Challenge Solution
var obj = {
a: {
b: {
c: 12
}
},
findPath :function (str) {
let x = str.split('.');
let ans = null;
for(let i = 0; i<= x.length - 1; i++){
21
I was having same problem with my title and after lots of searching, i found this answer Here,
var search = 'Joe';
db.users.find(name: /^search/)
db.users.find(name: {$regex: /^search/});
db.users.find(name: {$regex: "/^" + search + "/"});
The queries above won’t return anything. The solution to this little problem is quite simple:
exports.removeDuplicates = async (req, res) => {
let keywordlist = await Keyword.find();
/**get list */
for (let i = 0; i < keyword.length; i++) {
let singlekeyword = keywordlist[i];
/**get similar keyword without currentone */
let similarKeywords = await Keyword.find({
$and: [
{ keyword: new RegExp(singlekeyword.keyword, "i") },
{ _id: { $ne: singlekeyword._id } },
// let timeline = await Timeline.aggregate([
// { $match: { timelineTopic: timelineTopic } },
// {
// $group: {
// _id: "$date",
// shortDescription: { $addToSet: "$shortDescription" },
// longDescription: { $addToSet: "$longDescription" },
// articles: {
// $push: "$article",
// },
let timelines = await Timeline.find({
timelineTopic: timelineTopic,
}).populate({
path: "articles",
populate: {
path: "publisher",
model: "Publisher",
},
});
exports.getkeywordswithSkippingKeywords = async (req, res, next) => {
try {
const userId = req.userData.userId;
const limit = parseInt(req.params.limit);
const page = parseInt(req.params.page);
let keywords = await Keyword.aggregate([
{ $match: {} },
{ $sort: { count: -1 } },
{ $skip: limit * page },
const getPreferencesForLoggedinUser = async (req) => {
let userId = req.userData.userId;
let result = await Preference.aggregate([
{ $match: { user: mongoose.Types.ObjectId(userId) } },
{
$lookup: {
from: Keyword.collection.name,
localField: "keyword",
foreignField: "_id",
as: "keywordData",
let pref = await Preference.aggregate([
{ $sort: { _id: -1 } },
{
$facet: {
user: [
{
$lookup: {
from: User.collection.name,
localField: "user",
foreignField: "_id",