refactor with bind
This commit is contained in:
parent
1365ef65dd
commit
80bc9f083d
@ -32,11 +32,12 @@ table input {
|
||||
table td.table-primary input,
|
||||
table td.table-active input,
|
||||
table.table-success input,
|
||||
td.table-danger input:disabled,
|
||||
table input:not([disabled]) {
|
||||
background: transparent !important;
|
||||
}
|
||||
|
||||
table input[disabled] {
|
||||
table input:disabled {
|
||||
background-position: center !important;
|
||||
}
|
||||
|
||||
|
32
sudoku.js
32
sudoku.js
@ -178,18 +178,14 @@ function checkBox(box) {
|
||||
checkCandidates(box.andNeighbourhood)
|
||||
|
||||
if (box.value) {
|
||||
for (let [areaName, neighbours] of Object.entries({
|
||||
for (let [areaName, area] of Object.entries({
|
||||
région: regions[box.regionId],
|
||||
ligne: rows[box.rowId],
|
||||
colonne: columns[box.columnId],
|
||||
}))
|
||||
for (neighbour of neighbours)
|
||||
if (box != neighbour && box.value == neighbour.value) {
|
||||
for (neighbour of [box, neighbour]) {
|
||||
neighbour.setCustomValidity(`Il y a un autre ${box.value} dans cette ${areaName}.`)
|
||||
neighbour.classList.add("is-invalid")
|
||||
}
|
||||
}
|
||||
for (neighbour of area)
|
||||
if (box != neighbour)
|
||||
showDuplicates(areaName, box, neighbour)
|
||||
}
|
||||
|
||||
checkSuccess()
|
||||
@ -204,14 +200,7 @@ function checkBoxes() {
|
||||
colonne: columns,
|
||||
}))
|
||||
for (area of areas)
|
||||
area.sort((box, neighbour) => {
|
||||
if (box.value && box.value == neighbour.value) {
|
||||
for (neighbour of [box, neighbour]) {
|
||||
neighbour.setCustomValidity(`Il y a un autre ${box.value} dans cette ${areaName}.`)
|
||||
neighbour.classList.add("is-invalid")
|
||||
}
|
||||
}
|
||||
})
|
||||
area.filter(box => box.value).sort(showDuplicates.bind(null, areaName))
|
||||
|
||||
checkSuccess()
|
||||
}
|
||||
@ -220,6 +209,7 @@ function checkCandidates(area) {
|
||||
area.forEach(box => {
|
||||
box.setCustomValidity("")
|
||||
box.classList.remove("is-invalid")
|
||||
box.parentElement.classList.remove("table-danger")
|
||||
searchCandidatesOf(box)
|
||||
if (box.candidates.size == 0) {
|
||||
box.setCustomValidity("Aucun chiffre possible !")
|
||||
@ -228,6 +218,16 @@ function checkCandidates(area) {
|
||||
})
|
||||
}
|
||||
|
||||
function showDuplicates(areaName, box, neighbour) {
|
||||
if(box.value == neighbour.value) {
|
||||
area.forEach(neighbour => neighbour.parentElement.classList.add("table-danger"))
|
||||
for (neighbour of [box, neighbour]) {
|
||||
neighbour.setCustomValidity(`Il y a un autre ${box.value} dans cette ${areaName}.`)
|
||||
neighbour.classList.add("is-invalid")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function checkSuccess() {
|
||||
if (sudokuForm.checkValidity()) { // Correct grid
|
||||
if (boxes.filter(box => box.value == "").length == 0) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user