[x] Use the format provided below for your solutions
[x] Pair up with someone for at least 1 hour!
Practice / Reading:
[ ] Add more examples to your Reading-JavaScript.md file; use a branch and a PR like usual; you should probably break this line up into individual items; don't forget the checkboxes...!
[x] Write tests that verify that your "board" looks correctly at every step.
Using Objects instead of loose functions...
function toEnglish(value){ /* . . . */ }
// turn ^^ into vv
var CheckWriting = {
toEnglish: function(value){ /* . . . */ }
}
Project Euler Format
/* === PRODUCTION CODE === */
function solution(){
// change input to suit the solution, e.g. `limit`
return {
// I wanna see this one...
solveFor: function(limit){ /* perform magic... */ },
// For Problem 2, for example... However you solve it.
fibonacci: function(limit){ /* . . . */ },
filterEvens: function(list){ /* . . . */ },
sum: function(list){ /* . . . */ }
}
}
/* === TEST CODE === */
// You should probably write some...
Conway's Game of Life
var game = {
board: undefined,
newBoard: function(){ /* i.e. board() */ },
rules: function(cell, neighbors){ /* i.e. conway(cell, neighbors) */ },
neighborsOf: function(x,y){ /* . . . */ },
tick: function(){ /* accepts nothing, alters `game.board` */ },
/**
* WARNING: This is VOODOO MAGIC...
*
* GIVEN:
* this.board === [
* [ false, true, false ],
* [ false, true, false ],
* [ false, true, false ],
* ];
*
* EXPECT:
* +---+---+---+
* | | X | |
* +---+---+---+
* | | X | |
* +---+---+---+
* | | X | |
* +---+---+---+
*/
display: function(){
var spacer = '+---+---+---+\n';
return spacer +
// Apply `renderRow` to each `row` in `board`...
this.board.map(function renderRow(row){
return '| ' +
// Apply `renderCell` to each `cell` in `row`...
row.map(function renderCell(cell){
// return 'X' if `cell` is TRUTHY otherwise return ' '
return cell && 'X' || ' ';
}).join(' | ') // Place ' | ' between each `cell`...
+ ' |\n';
}).join(spacer) // Place `spacer` between each `row`...
+ spacer;
} // END display
} // END game
Resources:
New Concepts:
display()
function provided for "Conway"Practice / Reading:
Reading-JavaScript.md
file; use a branch and a PR like usual; you should probably break this line up into individual items; don't forget the checkboxes...!Array.prototype
Methods assignment from yesterday:Using Objects instead of loose functions...
Project Euler Format
Conway's Game of Life