Skip to content

Instantly share code, notes, and snippets.

@cryptoquick
Created September 12, 2015 07:19
Show Gist options
  • Save cryptoquick/29e6c544fd58c622d8fd to your computer and use it in GitHub Desktop.
Save cryptoquick/29e6c544fd58c622d8fd to your computer and use it in GitHub Desktop.
Computer Science Lessons

Primitive Data Types

  • Boolean (true, false)
  • String ("asdf")
  • Number
    • Integer (314)
    • Floating Point (3.14)
  • Enum ({ A, B, C })

Abstract Data Types

  • Array ([1,2,3])
  • Key / Value
    • A Map
    • A Object / Object Literal (JavaScript)
    • An Associative Array (PHP)
    • A Dictionary (Python)
    • A Hash (Ruby)
    • In JSON:
      {
        "Key": "value"
      }
    • O(1)
  • List
    • Meant to be iterated through
    • They can go in one direction or both (because they're a linear data type, you can only go in 2 possible directions)
    • .next(), .prev(), .val()
    • O(n)
  • Set
    • Based on Maps
    • {1, 2, 3} <- A valid Set
    • {1, 2, 1, 2, 3} <- Not a valid, but it is what's known as a Bag or Multiset
      • What SQL queries return
  • Queues and Stacks
    • Based on Lists
    • A queue is FIFO
    • A stack is LIFO
  • Tree
    • They have branches
    • It's the highest order data structure that JSON can contain
    • Good for searches
    • How most filesystems are kept
    • Can be balanced or weighted
    • Can have Depth-First Search, Breadth-First Search
  • Graph
    • Complex
    • Consist of Nodes / Vertices and Edges
    • Can describe relationships

Lesson

JSON Data Structures

{
  "key": "value",
  "object_key": {
    "name": "Nicole",
    "age": 27,
    "more_information": {
      "description": ""
    }
  },
  "array_key": [
    1.0,
    "string",
    2.9,
    "2.9.0",
    1
  ],
  "citiesAndZips": [
    {
      "city": "Denver",
      "zip": 80204
    },
    {
      "city": "Boulder",
      "zip": 80301
    },
    {
      "city": "Aurora",
      "zip": 80012
    },
    {
      "city": "Colorado Springs",
      "zip": 80000
    }
  ]
}
  • Arrays have order
  • Objects do not have order

Serialization

  • JSON.stringify(obj);
'{"key":"value","object_key":{"name":"Nicole","age":27,"more_information":{"description":""}},"array_key":[1,"string",2.9,"2.9.0",1],"citiesAndZips":[{"city":"Denver","zip":80204},{"city":"Boulder","zip":80301},{"city":"Aurora","zip":80012},{"city":"Colorado Springs","zip":80000}]}'
JSON.parse('{"key":"value","object_key":{"name":"Nicole","age":27,"more_information":{"description":""}},"array_key":[1,"string",2.9,"2.9.0",1],"citiesAndZips":[{"city":"Denver","zip":80204},{"city":"Boulder","zip":80301},{"city":"Aurora","zip":80012},{"city":"Colorado Springs","zip":80000}]}');

Control Structures

for loop

for (var i = 0; i < obj.array_key.length; i++) {
  console.log(i, obj.array_key[i]);
}
  • i++
    • Increments the i value
  • for loops have three parts, separated by colons:
    • for (initial value; conditional which is evaluated each time; increment)

for in loop

for (var key in obj.object_key) {
  var val = obj.object_key[key];
  console.log(key);
  console.log(val);
}

Array Methods

  • forEach(element, index)
  • map(element, index, array)
  • reduce(accumulator, key, val, array)
  • filter(one, two)

Terminology

  • REPL

Programming

  • Procedural
  • Object-oriented
  • Functional
    • Immutability
    • No Side-effects
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment