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 canvas = document.getElementById('canvas'), | |
ctx = canvas.getContext('2d'), | |
timeBetweenSprites = 100, // measured in in milliseconds | |
direction = "forward"; | |
canvas.width = 400; | |
canvas.height = 400; | |
// first figure out how big the spritesheet is (pixel dimensions) | |
var spritesheet = new Image(); |
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
//Tic Tac Toe game for the JavaScript console | |
//Constants | |
//Array of potential winning cell combinations | |
var winCells = [[1,2,3], [4,5,6], [7,8,9], [1,4,7], [2,5,8], [3,6,9], [1,5,9], [3,5,7]]; | |
//Board model | |
function Board() { |
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 mergeSort(arr) { | |
var len, arr1, arr2; | |
len = arr.length; | |
if (len===1) { | |
return arr; | |
} | |
//Split array in half | |
arr1 = arr.slice(0, Math.floor(len/2)); | |
arr2 = arr.slice(Math.floor(len/2)); | |
//Call mergeSort on each half |
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 findFirst(str, set) { | |
//Helper function to convert string into a hash object | |
function hashFromStr(str) { | |
var setHash = {}, | |
key; | |
for (var i=0, len=str.length; i<len; i++) { | |
key = str[i]; | |
if (setHash.hasOwnProperty(key)) { | |
setHash[key]++; | |
} else { |