JS Data Structure Notes
Published on 01/24/2019
2 min read
Data structures are collections of values, the relationships among them, and the functions or operations that can be applied to the data.
- used to store key-value pairs
- keys in a hash-table are not ordered
- very fast CRUD functionality.
- great for non-sequential data
const colors = ['#ff343', '#ff939', '#ff920']; // before hashing colors; // after hashing colors['cyan'];
Basic gist of a hash function is such that every time a unique input gets passed in, only one unique output is returned.
pink => 1 1 => pink
"a".charCodeAt(0) // 97, 97 is the char code at the 0th (first) value of the string on which the charCodeAt() function was called. "hi".charCodeAt(0) // 104 "hi".charCodeAt(1) // 105 // NEAT TRICK if you subtract 96, this gives us the 'alphabetic ranking', aka, "a" is the 1st letter in the alphabet. "a".charCodeAt(0) - 96 // 1
52 % 11 // 8 2351431234 % 11 // 9
whatever number we modulo by, we are guaranteed to get an output that is smaller than that number, no matter how large the first number is.
- there are no entry points, or start/finish. The nodes are treated equally, and the connections between them are part of the definition of the graph
- great fro recommendations and overlap analysis.
- i.e. two video games are linked by "war", "space", and "future", nodes.