Created
August 2, 2017 14:10
-
-
Save jshakes/7098ff0046bbc1de1a21f66aa51d5ec1 to your computer and use it in GitHub Desktop.
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 Sudoku = function(data) | |
{ | |
// Private methods | |
// ------------------------- | |
function makeColArr() { | |
let columns = []; | |
let valid = true; | |
data.forEach((row, rowIndex) => { | |
columns.push([]); | |
row.forEach((cell, cellIndex) => { | |
const colRow = data[cellIndex]; | |
const colCell = row[rowIndex]; | |
if(!cell) { | |
valid = true; | |
return; | |
} | |
columns[rowIndex].push(cell); | |
}); | |
}); | |
return valid ? columns: null; | |
} | |
// Public methods | |
// ------------------------- | |
return { | |
isValid: function() { | |
let rowsValid = true; | |
let columnsValid = true; | |
const columns = makeColArr(); | |
if(!columns) { | |
return false; | |
} | |
data.forEach((row, rowIndex) => { | |
row.forEach((cell, cellIndex) => { | |
column = columns[cellIndex]; | |
rowsValid = row && row.indexOf(cellIndex) > -1; | |
columnsValid = column && column.indexOf(cellIndex) > -1; | |
}); | |
}); | |
return rowsValid; | |
} | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment