Created
July 16, 2018 07:38
-
-
Save dschinkel/828cf5100237d30cc62c7921850b318f to your computer and use it in GitHub Desktop.
Medium Blog Post - Data Hiding, Instances, and Better Testing with JS Factories and Closures
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
let board; | |
resetToEmptyBoard(); | |
function getBoard() { | |
return board; | |
} | |
function cellIsEmpty(position){ | |
const empty = board[position] === ' '; | |
return empty; | |
} | |
function getEmptyCells(){ | |
const emptyCells = board.filter(cell => { | |
return cell === ' ' | |
}); | |
return emptyCells; | |
} | |
function resetToEmptyBoard(){ | |
board = [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']; | |
} | |
function setBoard(newBoard){ | |
board = newBoard; | |
} | |
function isFull(board){ | |
const emptyCells = board.filter(cell => { | |
return cell === ' ' | |
}); | |
return emptyCells.length === 0; | |
} | |
const Board = { | |
isFull, | |
getBoard, | |
getEmptyCells, | |
cellIsEmpty, | |
resetToEmptyBoard, | |
setBoard | |
}; | |
export default Board; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment