constrange=(length)=>Array.from({length},(_,k)=>k);// Returns a total of 27 arrays [ row0, col0, square0, ...., row8, col8, square8]functiongetArrays(sudoku){consttoXY=(i)=>({x:Math.floor(i/3),y:i%3});constgetRow=(i)=>sudoku[i];constgetCol=(i)=>range(9).map((cell)=>sudoku[cell][i]);constgetSquare=(i)=>range(9).map((cell)=>sudoku[3*toXY(i).x+toXY(cell).x][3*toXY(i).y+toXY(cell).y]);returnrange(9).flatMap((i)=>[getRow(i),getCol(i),getSquare(i)]);}// check if only numbers 1 to 9 are used in an arrayconstvalidateArray=(array)=>{constvalidSet=newSet(range(9).map((i)=>i+1));returnarray.every((number)=>validSet.has(number));};constcheckSudoku=(sudoku)=>getArrays(sudoku).every(validateArray);
Now this is not "my solution is better than yours", it is more of a - "different solutions to the same problem". We all are here to learn! I learned a bit from you and I really hope you learn something new from me too<3.
Please don't hesitate to ask any question!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Here is how I would solve this:
Now this is not "my solution is better than yours", it is more of a - "different solutions to the same problem". We all are here to learn! I learned a bit from you and I really hope you learn something new from me too<3.
Please don't hesitate to ask any question!