- Initial State of the game:
gameState = { appleCoord: {x: 5, y:5}, score: 0, canvas: null, canvasContext: null, framesPerSecond: 30, cw: 15, //cell width
//boardState is 2d array | |
//action is 2 length number string ex: "11" | |
//player is string of either "x" or "o" | |
//took longer time than allotted time | |
// Timur's comments: | |
// - Please indent your code to make it easier to read it! | |
// - Don't switch between es5 and es6. (var vs let) |
gameState = { appleCoord: {x: 5, y:5}, score: 0, canvas: null, canvasContext: null, framesPerSecond: 30, cw: 15, //cell width
var convertMapArr = function(keyValPair) { | |
queryMap = {} | |
var queue = keyValPair.reduce(function(keysArray, keyValArr) { | |
var firstArr = keyValArr[0]; | |
var key = firstArr[0]; | |
var value = keyValArr[1]; | |
var remainingChildren = firstArr.slice(1); | |
var keyExistsInMap = (key in queryMap); |
var parseString = function(/*string*/string) { /* array of strings */ | |
return string.split("&"); | |
} | |
var parseKeyValueString = function(/*array*/stringsArray) { | |
return stringsArray.reduce(function(subArray, keyValueString) { | |
var subArrayKeyValue = keyValueString.split("=") | |
return subArray.concat([subArrayKeyValue]); | |
},[]) | |
} |
var parseString = function(/*string*/string) { /* array of strings */ | |
return string.split("&"); | |
} | |
var parseKeyValueString = function(/*array*/stringsArray) { | |
return stringsArray.reduce(function(subArray, keyValueString) { | |
var subArrayKeyValue = keyValueString.split("%5B") | |
return subArray.concat([subArrayKeyValue]); | |
},[]) | |
} |
queryMap = { | |
address: "3400 stratford", | |
full_name: { | |
first_name: 'Timur', | |
last_name: 'Meyster' | |
}, | |
email: '[email protected]' | |
} | |
var turnMapToArray = function(queryMap) { |
// 1. Think about the Data | |
// -Get out all of the data that's relavent in the right shape | |
// -Funcitons that transform that data from one state to the next state | |
// | |
// Invarient: True for every game | |
// -2 Players | |
// -2 symbols for each player | |
// -Some Mapping between the player and the symbol | |
// -3x3 grid with a total of 9 squares |
queryMap = { | |
name: 'Timur', | |
last_name: 'Meyster', | |
email: '[email protected]' | |
} | |
var turnMapToArray = function(queryMap) { | |
var queryResult = [] | |
for (var key in queryMap) { | |
queryResult.push([key, queryMap[key]]) |
var parseString = function(/*string*/string) { /* array of strings */ | |
return string.split("&"); | |
} | |
var parseKeyValueString = function(/*array*/stringsArray) { | |
return stringsArray.reduce(function(subArray, keyValueString) { | |
var subArrayKeyValue = keyValueString.split("=") | |
return subArray.concat([subArrayKeyValue]); | |
},[]) |
var nestedListMatch = function(lists, match) { | |
var firstItem = lists[0]; | |
if(firstItem === match) { | |
return match; | |
}else if (Array.isArray(firstItem)){ | |
var result = nestedListMatch(firstItem, match) | |
if(result === match) { |