This file contains 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
// 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() { |
This file contains 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
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. |
This file contains 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
// 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) { |
This file contains 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
// 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; |
This file contains 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
// 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. |
This file contains 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
// 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) { |
This file contains 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
// 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++) { |
This file contains 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
// 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) |
This file contains 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
// 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]) { |
This file contains 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
// 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. |
NewerOlder