Here's a small refactor of the newPuzzle endpoint. Most of the changes are in the puzzleMapper module. The functions can be read from bottom to top, which each enclosed function being defined directly above the caller.
Some thoughts:
I don't think this is the best implementation but it's pretty good. We map over the letters to create an array of cell objects (which all have across and down default objects) and then we iterate over that array once more and each time we come across a gridnum we invoke a function that returns an array of indices for all the cells belonging to that clue (in either direction, we specify the direction as an argument when we invoke that function). Then we iterate that many steps and fill out the across/down object.
Another issue with this data model that I haven't addressed in the PR is the unnecessary nesting. It makes the invocation of the scanClueCells function a bit clunky. It would be better if the data model looked something like this:
const puzzleMapper = (puzzle) => ({
clueArrayAcross: puzzle.clues.across,
clueArrayDown: puzzle.clues.down,
acrossClueMap: clueMapper(puzzle.clues.across),
downClueMap: clueMapper(puzzle.clues.down)
cells: generateCellsObjectArray( // disregard this function call
puzzle.grid,
puzzle.gridnums,
puzzle.size,
clueMapper(puzzle.clues.across),
clueMapper(puzzle.clues.down),
puzzle.answers.across,
puzzle.clues.across,
puzzle.answers.down,
puzzle.clues.down
)
});
// and cells should look like this
const cells = grid.map((cell, index) => ({
index,
gridnums: gridnums[index],
letter: cell,
focus: false,
guess: "",
row: row(index),
column: column(index),
acrossmember: null,
downmember: null,
acrossStart: null,
downStart: null,
acrossClue: null,
downClue: null,
acrossAnswer: null,
downAnswer: null,
acrossPrev: null,
downPrev: null,
acrossNext: null
downNext: null
}));
Move the contents of acrossMember and downMember to the top level and get rid of focusRange. We already have that information in the othe fields. On the front end, when you click on a clue or a cell, we can modify the object that keeps track of our focus to the current direction and the associated clue along that direction (from the clicked on cell).
Another thing. We probably want to not include the answer data in each cell (or in the payload at all), as we'll make a call to the backend to validate a cell, word, or puzzle.
removed .yarnrc.yml
further yarn cleanup
removed yarn upgrade
lint fix
cleanup
initial commit
update
added docs
Updated docs
Added todo list
updated project tasks
updated notes
created skeleton for capstone project
updated webpack
updated readme
added some more notes to the docs
updated architecture diagram
Updated todos
Added another todo item
updated capstone skeleton
Readme markdown test
README markdown update
Removing dividers in README
Updating h in README
Added another todo in the README