This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SINGLE RESPONSIBILITY PRINCIPLE | |
class User { | |
constructor(name) { | |
this.name = name; | |
} | |
getName() { | |
return this.name; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let cache = {}; // just a simple js object | |
// cache is just some space in RAM (memory) | |
function getStudentDetailsFromDatabase(name) { // AWS - US east | |
return { | |
name: `${name} is a student`, | |
age: Math.floor(Math.random() * 100) | |
} // response time is n seconds | |
} | |
function main(name) { | |
if(cache[name]) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let cache = {}; // just a simple js object | |
// cache is just some space in RAM (memory) | |
function getStudentDetailsFromDatabase() { // AWS - US east | |
return { | |
name: 'John', | |
} // response time is n seconds | |
} | |
function main() { | |
if(cache["result"]) { | |
return cache["result"]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.collection.aggregate([ | |
{ $unwind: "$id" }, | |
{ $group: { | |
_id: "$id", | |
titles: { $push: "$title" } | |
}}, | |
{ $group: { | |
_id: null, | |
distinctDocuments: { $push: { id: "$_id", title: { $first: "$titles" } } } | |
}}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sum(a, b) { | |
return a + b; | |
} | |
function divide(a, b) { | |
return a / b; | |
} | |
function calculatePercentage(a, b) { | |
return divide(a, b) * 100; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let person = { | |
firstName: "Vikash", | |
lastName: "Sagar", | |
fullName: function() { | |
return this.firstName + " " + this.lastName; | |
} | |
} | |
console.log(person.fullName()); // Output: Vikash Sagar | |
let person1 = { | |
firstName: "John", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let string = "Enjoying my day at the beach! #beachday #day1"; | |
let pattern = /\w/g | |
// \w means any word character (equal to [a-zA-Z0-9_]) | |
// which means that \w includes underscore | |
// anything between a-z | |
// anything between A-Z | |
// anything between 0-9 | |
console.log(string.match(pattern)); | |
let patternNumber = /\d/g | |
// \d means any digit (equal to [0-9]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let string = "Anish is a student with alma better. So is Subrojyoti"; | |
let pattern = /[a-z]/g | |
// [a-z] means any character from a to z | |
// [A-Z] means any character from A to Z | |
// [0-9] means any character from 0 to 9 | |
console.log(string.match(pattern)); | |
let stringNew = "My age is 23. I was born in 1997"; | |
let patternNew = /[0-9]/g | |
// [0-9] is a range that matches any character from 0 to 9 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let string = `Hi! Recently India celebrated its Independence Day` | |
// 1. Find all 'e' and replace it with 'E' | |
// 2. Replace the 'Independence Dat' in the sentence with 'Republic Day' | |
// 3. Find the index of 'India' in the string | |
let string2 = "hello world how are you?"; | |
// 1. Find all the spaces in the string |