function sudoku(puzzle) {
while (puzzle.some( l => l.some( p => p===0 ) ))
for (let y=0; y<9; y++)
for (let x=0; x<9; x++)
if (puzzle[y][x]===0) {
let p = [true,true,true,true,true,
true,true,true,true,true];
for (let i = 0; i<9; i++) {
p[puzzle[y][i]] = false;
p[puzzle[i][x]] = false;
}
for (let i=3*~~(x/3); i<3*(~~(x/3)+1); i++)
for (let j=3*~~(y/3); j<3*(~~(y/3)+1); j++)
p[puzzle[j][i]] = false;
if (p.reduce( (p,c) => p+(c?1:0) ) === 1)
puzzle[y][x] = p.indexOf(true);
}
return puzzle;
}
// Since Node 10, we're using Mocha.
// You can use `chai` for assertions.
const chai = require("chai");
const assert = chai.assert;
// Uncomment the following line to disable truncating failure messages for deep equals, do:
// chai.config.truncateThreshold = 0;
// Since Node 12, we no longer include assertions from our deprecated custom test framework by default.
// Uncomment the following to use the old assertions:
// const Test = require("@codewars/test-compat");
describe("Solution", function() {
it("should test for something", function() {
// Test.assertEquals(1 + 1, 2);
// assert.strictEqual(1 + 1, 2);
});
});