Skip to content

Instantly share code, notes, and snippets.

View elishaking's full-sized avatar
🎯
Focusing

King Elisha elishaking

🎯
Focusing
View GitHub Profile
@elishaking
elishaking / euclidean-algorithm.md
Last active March 30, 2020 06:53
Summary of the three Euclidean Algorithms for computing GCD

Euclidean algorithm

The Euclidean algorithm is one of the oldest numerical algorithms commonly used to solve the problem of computing the greated common divisor (gcd) of two positive integers.

There are three main implementations of the Euclidean algorithm:

1. Euclidean algorithm by subtraction

Here, we recursively subtract the smaller number from the larger number

/**
@elishaking
elishaking / sieve-of-eratosthenes.md
Created March 24, 2020 08:36
Bried description of the Sieve of Eratosthenes

Sieve of Eratosthenes

The Sieve of Eratosthenes is a simple algorithm for finding all the prime numbers of [2, n]. It works by removing multiples of consecutive numbers.

const sieveOfEratosthenes = n => {
  // initially label every number from [0, n] as a prime number
  const primeNumbersSieve = new Array(n + 1).fill(true);

  // since 0 and 1 are not prime numbers, label them as false
@elishaking
elishaking / blazehub_user_stories.md
Last active March 22, 2020 11:43
User Stories for BlazeHub

User Stories for BlazeHub

Authentication

  • As a first-time user, I want to sign up so that I can have an account BlazeHub
  • As a returning user, I want to login to have access to my account on BlazeHub
  • As an active user, I want to save my login status in my current browser/app so that I can access my account without having to login

Security

@elishaking
elishaking / prefix-sums.md
Created February 20, 2020 19:46
Prefix Sums

Prefix Sums

Prefix sums is a tehnique that allows for the calculation of the sums M slices of a given array in constant time - O(1)

Given an array of length N, it's prefix sums can be calculated in linear time - O(N) like this

function prefixSums(A) {
  const sums = new Array(A.length + 1).fill(0);

Counting Elements

A numerical sequence can be represented by an array in two ways

// an arbitrary sequence can be represented like this
const A = [1, 1, 2, 2, 2, 4, 4, 8, 8];

The same sequence cn be represented by counting the number of occurrences of each element. The above sequence can be represented like this

@elishaking
elishaking / time-complexity.md
Created February 17, 2020 07:32
A summary of Time and Space Complexity

Time Complexity

Complexity refers to the maximum number of primitive operations a program may execute. It makes it easy to estimate the running time of a program, however, accurately calculating the time complexity can be a challenging process. It is usually measured in orders of magnitude.

When calculating complexity, the operation that is often repeated during execution is called the dominant operation. Special focus should be given to the dominant operation when calculating time complexity.

function sum(n) {
  let sum = 0;
 for (let i = 0; i < n; i++) {
@elishaking
elishaking / arrays.md
Last active February 17, 2020 10:12
Arrays

Arrays

An array is a data structure that can be used to store a collection of items. Imagine if you had to store a list of your favorite soccer players, an array is the best data structure for that.

Create an Array

In JavaScript, there are several ways to define and initialize an array

It can be initialized like this

@elishaking
elishaking / gitflow-workflow.md
Last active February 15, 2020 12:26
Gitflow Workflow in a nutshell

What is it?

The Gitflow workflow is a strict branching model that provides a robust framework for managing large projects and teams. This workflow assigns specific responsibilities to named branches in the repository and defines how and when they should interact.

How it works

The five main branches used in this workflow include

  • master branch
  • develop branch
@elishaking
elishaking / iterations.md
Created February 15, 2020 11:27
Iterations

Iterations

Iteration involves the repetition of a block of code several times until a desired task is complete.

In JavaScript, there are three main tools that can be used for iterations:

For Loop

The for loop is the best tool to use when the number of repetitions is known. If an operation needs to be performed on every element in an array of length N, it becomes clear that N operations are needed and the for loop can be used to accomplish this