DEV Community


Discussion on: Checking Sudoku with Functional JavaScript

rhysbrettbowen profile image
Rhys Brett-Bowen • Edited

you could make this a bit better by just flattening the data and using a utility like lodash's groupBy. Then you can do something like withIndexAsXY = (fn, index) => fn(index % 9, Math.floor(index / 9)); and use the above functions on flattened data like:

xyToSquare = (x, y) => .....
squareData = groupBy(flatten(sudokuData), partial(withIndexAsXY, xyToSquare));

which may seem more complicated - but it means things have become more reusable