- DS
- BFS
- Hash to count unique
- Linked List
- Tree
- Sorting Algorithms
- Design
- stystem design
- design patterns -> strategy pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // a simple pure function to get a value adding 10 | |
| const add = (n) => (n + 10); | |
| console.log('Simple call', add(3)); | |
| // a simple memoize function that takes in a function | |
| // and returns a memoized function | |
| const memoize = (fn) => { | |
| let cache = {}; | |
| return (...args) => { | |
| let n = args[0]; // just taking one argument here | |
| if (n in cache) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Time complexity: O(n^2) | |
| function findTriplets(arr, n) { | |
| arr.sort(); | |
| var l = arr.length; | |
| for (var i = 0; i < l; i++) { | |
| var j = i + 1, | |
| k = l - 1; | |
| while (j < k) { | |
| if (arr[i] + arr[j] + arr[k] < n) { | |
| j++; |
- Must resd blog
- Create react app
- Absolute imports: More details here
-
add a file called .env in the project root with the following contents:
NODE_PATH=src/ -
for vs code intellisense: create file jsconfig.json with
{
"compilerOptions": {- aim to promote code re-use
- offers the ability to add behaviour to existing classes in a system dynamically
- focuses on the problem of extending objects functionality
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Types.js - Constructors used behind the scenes | |
| // A constructor for defining new cars | |
| function Car( options ) { | |
| // some defaults | |
| this.doors = options.doors || 4; | |
| this.state = options.state || "brand new"; | |
| this.color = options.color || "silver"; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var myModule = (function() { | |
| var _private = { | |
| i: 5, | |
| get: function() { | |
| console.log( "current value:" + this.i); | |
| }, | |
| set: function( val ) { | |
| this.i = val; | |
| }, |
- A real-world analogy could be a typical airport traffic control system. A tower (Mediator) handles what planes can take off and land because all communications (notifications being listened out for or broadcast) are done from the planes to the control tower, rather than from plane-to-plane. A centralized controller is key to the success of this system and that's really the role a Mediator plays in software design.
- Another analogy would be DOM event bubbling and event delegation. If all subscriptions in a system are made against the document rather than individual nodes, the document effectively serves as a Mediator. Instead of binding to the events of the individual nodes, a higher level object is given the responsibility of notifying subscribers about interaction events.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // skeleton | |
| function Observer(){ | |
| this.update = function(){ | |
| // ... | |
| }; | |
| } | |
| // every observer must have an update method, so that it can do things once notified |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var mySingleton = (function () { | |
| // Instance stores a reference to the Singleton | |
| var instance; | |
| function init() { | |
| // Singleton | |
| // Private methods and variables |
NewerOlder