Skip to content

Instantly share code, notes, and snippets.

View tjeastmond's full-sized avatar
🥸
Grr data

TJ Eastmond tjeastmond

🥸
Grr data
View GitHub Profile
/**
* 10
* / \
* 4 17
* / \ / \
* 1 9 12 18
* /
* 22
*/
@tjeastmond
tjeastmond / Graph Representation as Adjacency List.md
Last active March 22, 2021 21:04
Graph Representation as Adjacency List

BFS & DFS Notes

Links

Fundamentally a graph is a data structure which is characterized by nonlinearity for representing connections of vertices (or nodes) and edges. By definition:

A graph is a data structure which consists of a finite set of nodes (or vertices) with a set of edges connecting a pair of nodes (or vertices).

@tjeastmond
tjeastmond / System Design.md
Last active March 24, 2021 00:00 — forked from vasanthk/System Design.md
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
@tjeastmond
tjeastmond / foo.js
Last active March 18, 2021 19:53
This was for a simple test on reversing a linked list
function log(msg) {
console.log(msg);
}
// reverse character array
const reverse = arr => {
if (arr.length === 1) return arr;
let left = 0;
let right = arr.length - 1;
while (left < right) {
[arr[left], arr[right]] = [arr[right], arr[left]];
left++;
right--;
// quicksort
const quicksort = (arr, left = 0, right = arr.length - 1) => {
if (left >= right) return;
const pivot = arr[Math.floor((left + right) / 2)];
const index = partition(arr, left, right, pivot);
quicksort(arr, left, index - 1);
quicksort(arr, index, right);
return arr;
};
/**
* Simple mergesort exercise
*/
const mergeSort = unsortedArray => {
if (unsortedArray.length <= 1) return unsortedArray;
const middle = Math.floor(unsortedArray.length / 2);
const left = unsortedArray.slice(0, middle);
const right = unsortedArray.slice(middle);
return merge(mergeSort(left), mergeSort(right));
@tjeastmond
tjeastmond / getNames.js
Created March 6, 2019 21:12
Because I couldn't not do it...
function getNames(person) {
const names = [];
names.push(person.name);
person.children.forEach(child => names.push(...getNames(child)));
return names;
}
const people = {
name: "Robin",
children: [
@tjeastmond
tjeastmond / innerScope.js
Created February 20, 2019 20:42
Helping someone with a JS question
function head() {
console.log("HEAD");
/* Some more logic that goes down here then will return function */
return function body(arg) {
console.log(arg);
function inner() {
console.log("INNER METHOD");
}
// return "SOMETHING USEFUL";
var memoizer = function(memo, func) {
var recur = function(n) {
var result = memo[n];
if (typeof result !== 'number') {
result = func(recur, n);
memo[n] = result;
}
return result;
};
return recur;