refactoring formatting

This commit is contained in:
StevanFreeborn
2022-05-27 09:52:03 -05:00
parent c495fb725e
commit 4b1eaf0615
2 changed files with 33 additions and 23 deletions
+8 -8
View File
@@ -185,7 +185,7 @@ class SudokuSolver {
// transform character array into
// 2-d array with each element representing a row
// that contains an array of column values
let generateBoard = (puzzleValues) => {
let createBoard = (puzzleValues) => {
let board = [[], [], [], [], [], [], [], [], []]
let boardRow = -1
@@ -211,7 +211,7 @@ class SudokuSolver {
return board;
}
let canPlace = (board, row, col, value) => {
let checkPlacement = (board, row, col, value) => {
// verify that the value can be
// placed in the given column
@@ -256,7 +256,7 @@ class SudokuSolver {
}
let solveFromCell = (board, row, col) => {
let solveForGivenCell = (board, row, col) => {
// reset column and increment
// row when end of row reached
@@ -279,7 +279,7 @@ class SudokuSolver {
// next cell
if (board[row][col] != '.') {
return solveFromCell(board, row, col + 1);
return solveForGivenCell(board, row, col + 1);
}
@@ -291,11 +291,11 @@ class SudokuSolver {
let valueToPlace = i.toString();
if (canPlace(board, row, col, valueToPlace)) {
if (checkPlacement(board, row, col, valueToPlace)) {
board[row][col] = valueToPlace;
if (solveFromCell(board, row, col + 1) != false) {
if (solveForGivenCell(board, row, col + 1) != false) {
return board;
@@ -313,8 +313,8 @@ class SudokuSolver {
}
// get the solution for the given puzzle
let board = generateBoard(puzzle);
let solution = solveFromCell(board, 0, 0);
let board = createBoard(puzzle);
let solution = solveForGivenCell(board, 0, 0);
if (solution == false) return false;
return solution.flat().join('');
+25 -15
View File
@@ -11,46 +11,56 @@ const runner = require('./test-runner');
const app = express();
app.use('/public', express.static(process.cwd() + '/public'));
app.use(cors({ origin: '*' })); //For FCC testing purposes only
app.use(cors({ origin: '*' }));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
//Index page (static HTML)
app.route('/')
.get(function (req, res) {
res.sendFile(process.cwd() + '/views/index.html');
});
app.route('/').get((req, res) => {
//For FCC testing purposes
res.sendFile(process.cwd() + '/views/index.html');
});
apiRoutes(app);
fccTestingRoutes(app);
// User routes
apiRoutes(app);
//404 Not Found Middleware
app.use(function (req, res, next) {
app.use((req, res, next) => {
res.status(404)
.type('text')
.send('Not Found');
});
//Start our server and tests!
const PORT = process.env.PORT || 3000
app.listen(PORT, function () {
app.listen(PORT, () => {
console.log("Listening on port " + PORT);
// process.env.NODE_ENV='test'
if (process.env.NODE_ENV === 'test') {
console.log('Running Tests...');
setTimeout(function () {
setTimeout(() => {
try {
runner.run();
} catch (error) {
console.log('Tests are not valid:');
console.error(error);
}
}, 3500);
}
});
module.exports = app; // for testing