Skip to content

Instantly share code, notes, and snippets.

View waterrmalann's full-sized avatar
🎯
Focusing

Alan waterrmalann

🎯
Focusing
View GitHub Profile
@waterrmalann
waterrmalann / whatsapp_community_extractor.js
Last active June 17, 2024 14:14
A script to extract all numbers from a Whatsapp community which you're an admin of.
// A script to extract numbers of all members of a Whatsapp Community
// The client should be a "Community Admin" before running this script.
const CONTAINER_IDENTIFIER = '.xyw6214.x78zum5.x1r8uery';
const NUMBER_IDENTIFIER = '.x15g3fpr span.x1iyjqo2';
const SIDE_NUMBER_IDENTIFIER = 'span._ao3e';
const COMMUNITY_NAME = 'span.x1lliihq.xh8yej3';
const DEF_DELAY = 200;
function grabNormalNumbers() {
@waterrmalann
waterrmalann / maxBinaryHeap.js
Created June 20, 2023 15:38
JavaScript implementation of Maximum Binary Heap
class MaxBinaryHeap {
constructor() {
this.values = new Array();
}
// Insert a value into the heap.
insert(value) {
// Push the value into the heap.
this.values.push(value);
// We now need to bubble it up until it reaches the correct position.
@waterrmalann
waterrmalann / heapSort.js
Created June 20, 2023 15:38
A simple JavaScript implementation of Heap Sort algorithm using Min Binary Heap.
// A heap sort implementation in JavaScript.
// Implement a minimum binary heap data structure for the sorting to work with.
class MinBinaryHeap {
constructor() {
this.values = [];
}
// Insert a value into the heap.
insert(value) {
@waterrmalann
waterrmalann / binarySearchTree.js
Created June 20, 2023 07:07
JavaScript implementation of Binary Search Tree
// JavaScript Implementation of Binary Search Tree (w/ DFS, BFS)
class Node {
constructor(value) {
// We hold a value for each node.
this.value = value;
// A left pointer to the smaller node.
this.left = null;
// A right pointer to the larger node.
this.right = null;
@waterrmalann
waterrmalann / trie.js
Created June 19, 2023 15:04
A simple JavaScript implementation of Trie data structure.
// An implementation of a Trie Data Structure
// - All letters are assumed to be lowercase english alphabets.
class Node {
constructor(value) {
// We store a character as the value.
this.value = value;
// A marker for if the node signifies an end of a word.
this.isEndofWord = false;
// The 26 (lowercase alphabet) children node links.
@waterrmalann
waterrmalann / mergeSort.js
Created June 11, 2023 07:29
A simple JavaScript implementation of Merge Sort algorithm.
// Implementation of Mege Sort in JavaScript.
function merge(arr1, arr2) {
// Function to merge two sorted arrays together.
// We start our two pointers from the start of both arrays.
let i = 0, j = 0;
// We allocate a new array to hold the sorted values.
let merged = new Array();
// We loop as long as the two pointers are within the array.
while (i < arr1.length && j < arr2.length) {
@waterrmalann
waterrmalann / quickSort.js
Created June 9, 2023 15:40
A simple JavaScript implementation of Quick Sort algorithm.
// Implementation of Quick Sort in JavaScript
function pivot(arr, start = 0, end = arr.length - 1) {
// Get the value at our pivot point, which we assume as our first element.
let pivotValue = arr[start];
// We start the swapping index at the pivot point.
let swapIndex = start;
// We start a loop from the second element in the (sub)array.
for (let i = swapIndex + 1; i <= end; i++) {
@waterrmalann
waterrmalann / insertionSort.js
Created June 8, 2023 14:06
A simple JavaScript implementation of Insertion Sort algorithm.
// Simple implementation of Insertion Sort in JavaScript.
function insertionSort(arr) {
// We start from the element at index of 1 and look backwards.
for (let i = 1; i < arr.length; i++) {
// We store the value of where we started.
let temp = arr[i];
// Calculate the index of the element before.
let prev = i - 1;
// As long as prev is greater than or equal to 0 (base condition)
@waterrmalann
waterrmalann / selectionSort.js
Created June 7, 2023 15:33
A simple JavaScript implementation of Selection Sort algorithm.
// Simplified implementation of Selection Sort in JavaScript.
function selectionSort(arr) {
// We loop over the entire array.
for (let i = 0; i < arr.length; i++) {
// We assume the lowest value to be at index position `i`.
let lowest = i;
// We run a loop from `i + 1` till the end of the array.
for (let j = i + 1; j < arr.length; j++) {
if (arr[j] < arr[lowest]) {
@waterrmalann
waterrmalann / bubbleSort.js
Created June 7, 2023 14:34
A simple, optimized implementation of Bubble Sort algorithm in JavaScript.
// A simple, optimized bubble sort implementation in JavaScript.
function bubbleSort(arr) {
let len = arr.length; // keep track of the length.
let swapped = false; // keep track of if any swaps were made.
for (let i = 0; i < len - 1; i++) {
// Loop through all the elements of the array.
// We did `len - 1` because otherwise an unnecessary pass will be made at the end.
// We assume that no swap is taking place this pass.