Skip to content

Instantly share code, notes, and snippets.

@Prottoy2938
Prottoy2938 / ch-key-generation.js
Created November 2, 2020 13:17
Cipher Delta key generation code
function makeId(length) {
let result = "";
const characters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
const charactersLength = characters.length;
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
@Prottoy2938
Prottoy2938 / asdfadf.js
Last active August 22, 2020 08:47
asdfadf
//get the nth number in fibonacci sequence, base case is 0 and 1.
//solution 1, easier to understand but it's not good. It has a time complexity of O(2^n).
function fib(num) {
if (num === 2) return 1;
if (num === 1) return 0;
return fib(num - 1) + fib(num - 2);
}
fib(6) //returns 5
@Prottoy2938
Prottoy2938 / device-data-placeholder.js
Created May 10, 2020 05:32
Front-end demo JSON api with comments
{
"Status": "Connected",
"Adminstration Control": {
"Connection": "stable",
//Total number 100. 70 means adminstration can control most of stuff of that device, but he is restricted on some of the part.
//will need to think more about it
"Permission": "70" //rank system. 70 out of 100
},
"Device": {
//get the nth number in fibonacci sequence, base case is 0 and 1.
//solution 1, easier to understand but it's not good. It has a time complexity of O(2^n).
function fib(num) {
if (num === 2) return 1;
if (num === 1) return 0;
return fib(num - 1) + fib(num - 2);
}
fib(6) //returns 5
@Prottoy2938
Prottoy2938 / fibonacci-sequence.js
Created March 19, 2020 10:29
Generates Fibonacci Sequence and returns it in an Array, base case is 0 and 1.
// Get Fibonacci Sequence in an Array, base case is 0 and 1.
const fibSequence = (num) => {
if(num === 0) return 0;
const arr=[0,1];
let counter=2;
while(counter <=num){
arr[counter]=arr[counter -1] + arr[counter -2]
counter ++
}
@Prottoy2938
Prottoy2938 / Binary Search Tree Validation.js
Created March 18, 2020 14:50
Binary Search Tree Validation in JavaScript
//Solution 1
const isValidBST = function(root, min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER) {
if(root == null) return true
if(root.val >= max || root.val <= min) return false
return isValidBST(root.left, min, root.val) && isValidBST(root.right, root.val, max)
};
@Prottoy2938
Prottoy2938 / Dijkstra's-algorithm.js
Created March 18, 2020 10:02
Dijkstra's algorithm implementation in JavaScript
//Dijkstra algorithm is used to find the shortest distance between two nodes inside a valid weighted graph. Often used in Google Maps, Network Router etc.
//helper class for PriorityQueue
class Node {
constructor(val, priority) {
this.val = val;
this.priority = priority;
}
}
@Prottoy2938
Prottoy2938 / Dijkstra's-algorithm-Naive.js
Created March 18, 2020 09:57
Dijkstra's-algorithm implementation in JavaScript. This is the naive version, `PriorityQueue` class can be upgraded to a faster queue.
//Helper class. To get the most prioritize result out
class PriorityQueue {
constructor() {
this.values = [];
}
enqueue(val, priority) {
this.values.push({ val, priority });
this.sort();
}
dequeue() {
@Prottoy2938
Prottoy2938 / What's A Tree.txt
Created March 12, 2020 06:48
Tree Data Structure
In graph theory, a tree is an undirected graph in which any two vertices are connected by exactly one path,
or equivalently a connected acyclic undirected graph.
Which means, in a graph, we can reach a certain node in many different ways, but in a tree there should be only ONE way to reach that node.
@Prottoy2938
Prottoy2938 / Depth First Search.js
Last active March 13, 2020 05:56
Depth First Search Implementation in JavaScript. Works in Binary Tree
//The algorithm starts at the root node and explores as far as possible along each branch before backtracking
//To simplify, In Depth First Search in Binary Search Tree, travels through one side until it reaches its end and then tries the other side.
//============================================================================================================
//DFS_PreOrder
//This method, visits the one specific side(either left or right) at once, and after the whole side is finished, then visits the other side.
// as it goes through the tree, it pushes visited node continuously.
//Example: 10
// 6 15
// 3 8 20