Skip to content

Instantly share code, notes, and snippets.

@JordanMajd
JordanMajd / lineardatastructures.md
Last active April 6, 2016 21:51
Linear Data Structures

Linear Data Structures

Understanding different data structures and when to use them essential as a computer programmer. While many data structures are often hidden away behind layers of abstraction everything we do is built upon these patterns. This knowledge will not only eventually allow you to understand the software layers underneath the abstraction but also help you understand the hardware layer. In addition, these structures introduce a whole new toolset to help you solve problems on a day to day basis. If you study the internals of frameworks like Express and Angular you will find these patterns are relevant and powerful.

A linear data structure is a structure wherein all data elements are adjacent to each other. An array is an example of a linear data structure.

Stack

A stack is one of the most foundational yet simplest data structures. A stack is a linear data structure which is used to store data, it uses LIFO ordering, that is the last item into the stack is the first item out.

// Stack constructor
// properties:
// values: some way of storing data.
const Stack = function(){
// create the values property and assign it the value of an array literal.
this.values = [];
};
// pop
// description:
'use strict';
// Queue constructor
// properties:
// values: some way of storing data.
const Queue = function(){
// create the values property and assign it the value of an array literal.
this.values = [];
};
{
"tagname-lowercase": true,
"attr-lowercase": true,
"attr-value-double-quotes": true,
"doctype-first": true,
"tag-pair": true,
"spec-char-escape": true,
"id-unique": true,
"src-not-empty": true,
"attr-no-duplication": true,
{
// JSHint Default Configuration File (as on JSHint website)
// See http://jshint.com/docs/ for more details
"maxerr" : 50, // {int} Maximum error before stopping
// Enforcing
"noyield" : true, // true: functions dont need yield
"bitwise" : false, // true: Prohibit bitwise operators (&, |, ^, etc.)
"camelcase" : false, // true: Identifiers must be in camelCase
@JordanMajd
JordanMajd / index.html
Last active May 11, 2016 18:42
Where Is Waldo?
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Where is Waldo?</title>
<style>
#wenda {
display: none;
}
</style>
@JordanMajd
JordanMajd / xhr-example.js
Created May 18, 2016 02:24
This is an example of how to make an HTTP request using vanilla JS.
'use strict';
// Step One:
//
// in order to make an HTTP request we need an XMLHTTPRequest (XHR) object.
// Action: use new XMLHttpRequest() to create an XMLHttpRequest object and assign it to a variable.
var req = new XMLHttpRequest();
// The variable now holds an XMLHttpRequest object, which looks something like this:
//
// req = {
# Intro to Node (again)
## Objectives
By the end of this article you will be able to:
- Understand what APIs Node comes with and how they differ from the ones a web browser offers.
- Be able to use the REPL
- Be able to explain the history of Node and why it is so useful.

Asymptotic Notation

This is a brief intro to computational complexity and asymptotic notation. It may not cover some items in depth enough, in which case please refer to the resource materials below.

Objectives

  • Understand what computational complexity is.
  • Understand why asymptotic notation is used to describe computational complexity.
  • Be able to find the Big O for a given algorithm.
'use strict';
// Test flatten
assertArray(flatten([[1, 2, [3]], 4]), [1, 2, 3, 4]);
assertArray(flatten([0, [[[[1]]], [[2, [3]]], 4], [5, 6]]), [0, 1, 2, 3, 4, 5, 6]);
// Test throws type error with array values other than integer
assertError(flatten, TypeError, [0, ["string", [2]]]);
// Test throws type error for arr