We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see ourdocumentation.
There was an error while loading.Please reload this page.
2 parents4cc5d18 +f778147 commitad8ed00Copy full SHA for ad8ed00
31-40/36. Valid Sudoku.js
@@ -1,23 +1,29 @@
1
varisValidSudoku=function(board){
2
+// create variable to store row , col and box values
3
letrow=[]
4
letcol=[]
5
letbox=[]
6
+// loop i over 0-8
7
for(leti=0;i<=8;i++){
8
+// loop j over 0-8
9
for(letj=0;j<=8;j++){
10
+// this will help us get position of each cell from board
11
letIndI=3*Math.floor(i/3)+Math.floor(j/3)
12
letIndJ=3*(i%3)+(j%3)
13
+// check if value is already in row , col or box and return false
14
if(row.indexOf(board[i][j])!=-1){returnfalse}
15
if(col.indexOf(board[j][i])!=-1){returnfalse}
16
if(box.indexOf(board[IndI][IndJ])!=-1){returnfalse}
-
17
+// if not then add value to row , col and box
18
if(board[i][j]!='.'){row.push(board[i][j])}
19
if(board[j][i]!='.'){col.push(board[j][i])}
20
if(board[IndI][IndJ]!='.'){box.push(board[IndI][IndJ])}
21
}
22
+// reset row , col and box array
23
row=[]
24
col=[]
25
box=[]
26
27
28
returntrue
-}
29
+}