Skip to content

Instantly share code, notes, and snippets.

View codyromano's full-sized avatar

Cody Romano codyromano

  • Facebook
View GitHub Profile
function* fibGenerator() {
const series = [0, 1];
while (true) {
const last = series[1];
const beforeLast = series.shift();
const next = last + beforeLast;
series.push(next);
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);
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",
const object1 = {
people: {
Alex: {
occupation: 'SDE',
employers: {
Amazon: {
founder: 'Jeff Bezos',
locations: {
'Seattle': 'Headquarters'
}
@codyromano
codyromano / find_anagrams_in_word_list.js
Created May 17, 2017 17:18
Given a list of words, return the words that are anagrams of each other
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
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('');
{
"env": {
"browser": true,
"commonjs": true,
"es6": true
},
"jsx-uses-vars": true,
"extends": "eslint:recommended",
"parserOptions": {
"ecmaFeatures": {
<style>
main {
max-width: 50rem;
margin: 0 auto;
font-family: Helvetica;
font-size: 1.25rem;
}
.main-col {
display: flex;
}
function getRandomSex() {
return (Math.random() > 0.50) ? 'male' : 'female';
}
/**
* @private
* @returns {String}
*/
function generateName(gender, parents = []) {
}
@codyromano
codyromano / topo.js
Last active December 28, 2017 14:02
const hasIncomingEdges = node => node.edges.length;
const noIncomingEdges = node => !node.edges.length;
function removeEdge(adjacentVertex, node) {
node.edges = node.edges.filter(vertex => vertex !== adjacentVertex);
return node;
}
function topologicalSort(nodes = []) {
let noEdges = nodes.filter(noIncomingEdges),