Created
October 19, 2017 01:38
-
-
Save tonymtz/a546d7184d7cc85ff270d8f714e1d67b to your computer and use it in GitHub Desktop.
Fills a block with zeros given the block number, hardcoded for a sudoku grid.
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
// Fills a block with zeros given the block number, hardcoded for a sudoku grid. | |
// The "grid" must be a lineal array and must have 81 elements exactly. | |
// how to use it... | |
let grid = fillBlock(sudokuStoreMock.grid, 4); | |
function fillBlock(grid, blockNumber) { | |
let newGrid = grid.slice(0, grid.length); | |
blockNumber = blockNumber || 0; | |
let startPoints = [0, 3, 6, 27, 30, 33, 52, 55, 58]; | |
/* | |
* 0 3 6 | |
* 27 30 33 | |
* 52 55 58 | |
*/ | |
let pointer = startPoints[blockNumber]; | |
for (let index = 0; index < 9; index += 1) { | |
newGrid[pointer] = 0; | |
if ((pointer + 1) % 3 === 0 && pointer !== startPoints[blockNumber]) { | |
pointer = pointer + 6; | |
} | |
pointer++; | |
} | |
return newGrid; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment