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
| /* | |
| Initial questions: | |
| - How large is the grid? | |
| - What is the format of the input I'm given? | |
| - Is the player guaranteed to exist on the grid? | |
| - Is there always going to be a blocking tile? | |
| Proposal: dynamic programming | |
| - If adjacent tile is out of bounds (e.g. we're at |
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 getCalculateRegex = operator => new RegExp( | |
| '([0-9]+) ?\\' + operator + ' ?([0-9]+)', 'ig' | |
| ); | |
| const operations = [ | |
| { operator: '*', fn: (n1, n2) => n1 * n2 }, | |
| { operator: '/', fn: (n1, n2) => n1 / n2 }, | |
| { operator: '+', fn: (n1, n2) => n1 + n2 }, | |
| { operator: '-', fn: (n1, n2) => n1 - n2 } | |
| ]; |
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* fibGenerator() { | |
| const series = [0, 1]; | |
| while (true) { | |
| const last = series[1]; | |
| const beforeLast = series.shift(); | |
| const next = last + beforeLast; | |
| series.push(next); |
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 onDataReceived(data) { | |
| console.log(`Data from server: ${data}`); | |
| } | |
| function getReccos(username) { | |
| // Set up the AJAX request. | |
| const xhr = new XMLHttpRequest(); | |
| // Open the connection. | |
| xhr.open('GET', `/send_reccos?username=${username}`, true); |
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 Trie { | |
| constructor() { | |
| // The tree containing letters as nodes | |
| this.contents = {}; | |
| } | |
| addString(string) { | |
| let pointer = this.contents; | |
| /* The position of each letter in the string dicates | |
| its depth in the tree. For instance, in "bacon", |
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 object1 = { | |
| people: { | |
| Alex: { | |
| occupation: 'SDE', | |
| employers: { | |
| Amazon: { | |
| founder: 'Jeff Bezos', | |
| locations: { | |
| 'Seattle': 'Headquarters' | |
| } |
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 hashByFrequency(word) { | |
| // Initialize an array with an integer for each letter (a-z) | |
| let letters = new Array(25); | |
| for (let i=0; i<letters.length; i++) { | |
| letters[i] = 0; | |
| } | |
| let chars = word.split(''); | |
| chars.forEach(char => { | |
| // "a" has a character code of 96, so by subtracting 96, we can |
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 isObject = input => typeof input === 'object' && input !== null; | |
| /** | |
| * @returns {Object} An object literal representing a trie of strings | |
| */ | |
| function createTrie(strings = []) { | |
| return strings.reduce((trie, string) => { | |
| let pointer = trie; | |
| const chars = string.split(''); |
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
| { | |
| "env": { | |
| "browser": true, | |
| "commonjs": true, | |
| "es6": true | |
| }, | |
| "jsx-uses-vars": true, | |
| "extends": "eslint:recommended", | |
| "parserOptions": { | |
| "ecmaFeatures": { |
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
| <style> | |
| main { | |
| max-width: 50rem; | |
| margin: 0 auto; | |
| font-family: Helvetica; | |
| font-size: 1.25rem; | |
| } | |
| .main-col { | |
| display: flex; | |
| } |