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
| #!/usr/bin/env node | |
| const NKEYS = 4; | |
| function arrayOfSize(size) { | |
| var a = Array(size); | |
| for (var i = 0; i < size; i += 1) | |
| a[i] = null; |
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
| 'use strict'; | |
| class Node { | |
| constructor(data) { | |
| this.data = data; | |
| this.left = undefined; | |
| this.right = undefined; | |
| } |
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
| 'use strict'; | |
| function BinarySearchTree() { | |
| this.root = null; | |
| } | |
| BinarySearchTree.prototype.insertNode = function (val) { | |
| var node = { | |
| data : val, |
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
| 'use strict'; | |
| /* | |
| * Binary search tree with in-order iteration. | |
| * http://greim.github.io/gen/dist/00-intro.html | |
| */ | |
| class Tree { | |
| add(value) { | |
| if (this.root) this.root.add(value); |
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
| const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args))) | |
| // Usage : compose functions right to left | |
| // compose(minus8, add10, multiply10)(4) === 42 | |
| // | |
| // The resulting function can accept as many arguments as the first function does | |
| // compose(add2, multiply)(4, 10) === 42 |
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
| function createStore(reducer) { | |
| var state; | |
| var listeners = [] | |
| function getState() { | |
| return state | |
| } | |
| function subscribe(listener) { | |
| listeners.push(listener) |
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
| class Observer { | |
| subscribe(subscriber) { | |
| this.subscribers.push(subscriber); | |
| } | |
| publish(event, data) { | |
| let query = this.subscribers.filter(subscriber => subscriber.event === event); | |
| if (query.length) query.forEach(subscriber => subscriber.action(data)); | |
| } | |
| constructor() { | |
| this.subscribers = []; |
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
| /* Class representing a Trie data structure */ | |
| export default class Trie { | |
| /** | |
| * Creates a Trie | |
| * @return {Object} Trie | |
| */ | |
| constructor() { | |
| this.words = 0; | |
| this.prefixes = 0; |
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
| /* | |
| TRIES | |
| A trie (or radix tree) is a simple data structure that represents a set of values stored against a | |
| tokenizable key (usually strings). Each edge in a Trie represents a token in a key. A key is present in the trie if | |
| (1) There exists a path (e1..en) from the root such that the key = <token(e1), token(e2)...token(en)> and | |
| (2) there is some value at the path's terminal vertex vn. | |
| Let k = length(key). Then time complexity for lookup, insertion and deletion for a Trie is O(k). |
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
| // Async/Await requirements: Latest Chrome/FF browser or Babel: https://babeljs.io/docs/plugins/transform-async-to-generator/ | |
| // Fetch requirements: Latest Chrome/FF browser or Github fetch polyfill: https://github.com/github/fetch | |
| // async function | |
| async function fetchAsync () { | |
| // await response of fetch call | |
| let response = await fetch('https://api.github.com'); | |
| // only proceed once promise is resolved | |
| let data = await response.json(); | |
| // only proceed once second promise is resolved |
OlderNewer