Javascript Blog Posts

DeDuplication-ReDuplication

This article helps you to deduplicate a string given a string and chunk size.
Case : Lets say you have a large text file. Each row contains an email id and some other information (say some product-id). Assume there are millions of rows in the file. How would you effieciently de duplicate the data ?
DeDuplication : The process that returns an intermediate strinig , helps in reduplication of original string.
Steps to follow :
1. Break the string into chunks of the given size (Values of chunk size can be 1KB,10KB and so on).
2. Find the unique chunks and make a note of where these chunks occur in the string.
3. The intermediate string should contain the unique strings and their positions.

0 Likes 6089 Views
Remove elements from javascript array

The main aim of this article is to show case the ways to remove elements from a javascript array
ar = [1,2,3,4,5,6]
Procedure1 : splice is a built in method of javascript array. This is the best method to remove elements . It just takes two parameters index defines where to starts from and the next is the number defines how many elements to be removed.
ar.splice(ind, noOfElementsToRemove)
Ex:
If a user want to remove 2nd element from the ar. Ex :ar.splice(1, 1)
If a user want to remove 2nd and 3rd elements from the ar. Ex: ar.splice(1, 2)

0 Likes 1304 Views
How to reference documents in Mongodb

This article is helpful for those who are seriously looking and finding the usecase of reference documents in MongoDB. Referencing comes when we are saving data to database , that thing we obiously do through axios (Most Popular). Just place the below code inside any router where you want to and check the results.
Saving refs to other documents works the same way you normally save properties, just assign the _id value:
let Team = require('./team.model');
let Player = require('./player.model');
const team = new Team({
_id: new mongoose.Types.ObjectId(),
Name: 'KoderPlace',

0 Likes 1282 Views