This file contains 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
// deepEqual takes two variables and tests for property/value equality, recursively for objects. | |
// Idea for function and some examples for testing borrowed from ch.4 in Marijn Haverbeke's "Eloquent Javascript". | |
function deepEqual(obj1, obj2) { | |
if (typeof obj1 === typeof obj2) { | |
if (obj1 === obj2) { | |
return true; | |
} else if (obj1 && obj2) { |
This file contains 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 readline = require('readline'); | |
var rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout | |
}); | |
function printBoard(board) { | |
console.log(` |
This file contains 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 chooseMove(board) { | |
function getAvailableLocations() { | |
var availableLocations = []; | |
for (var location in board) { | |
// Since key === value is the default, if this is true, | |
// it means the spot has not yet been played. | |
if (location === board[location]) { |
This file contains 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
process.stdin.resume(); | |
process.stdin.setEncoding('ascii'); | |
var input_stdin = ""; | |
var input_stdin_array = ""; | |
var input_currentline = 0; | |
process.stdin.on('data', function (data) { | |
input_stdin += data; | |
}); |
This file contains 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 Queue(originalQueue) { | |
let queue = originalQueue || []; | |
function removeElement(q, i) { | |
const index = i === 'last' ? q.length - 1 : i; | |
if (!q[index + 1]) { | |
q[index] = undefined; | |
q.length = q.length - 1; | |
} | |
} |
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title></title> | |
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/tachyons/4.5.5/tachyons.min.css"> | |
</head> | |
<body class="sans-serif center" style="width:80%; display: flex; justify-content: center; flex-wrap: wrap"> | |
<div style="width: 100%"> | |
<button class="bg-orange" style="margin: 30px; height:160px; width: 260px" onclick="playGame()"> |
This file contains 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 fs = require('fs'); | |
const readline = require('readline'); | |
const rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout | |
}); | |
const tsvFileName = process.argv[2]; |
This file contains 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 nodes = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']; | |
const tree = { node: nodes[0], children: [{}, {}] }; | |
addNodes(tree.children[0], nodes[1], 1); | |
addNodes(tree.children[1], nodes[2], 2); | |
function addNodes(theRoot, node, index) { | |
if (!nodes[index]) { |
This file contains 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 words = ['dark', 'dapper']; | |
let trie = []; | |
words.forEach(word => { | |
addToTrie(word, 0, trie); | |
}); |
This file contains 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 vertices = ['james', 'jon', 'joe', 'moe', 'moda']; | |
const vertices2 = ['jon', 'joe', 'moe']; | |
const vertices3 = ['james', 'joe', 'moda']; | |
const edges = [['james', 'jon'], ['james', 'joe'], ['jon', 'joe'], ['joe', 'moe'], ['moe', 'moda'], ['moda', 'james']]; | |
const edges2 = [['jon','joe'], ['joe', 'moe'], ['moe', 'jon']]; | |
const edges3 = [['james', 'joe'], ['moda', 'james']]; | |
function createAdjacencyList(vertices, edges) { |
OlderNewer