Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitad8ed00

Browse files
authored
Merge pull request#14 from Tahirc1/Tahirc1-update-36
Update 36. Valid Sudoku.js
2 parents4cc5d18 +f778147 commitad8ed00

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

‎31-40/36. Valid Sudoku.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
varisValidSudoku=function(board){
2+
// create variable to store row , col and box values
23
letrow=[]
34
letcol=[]
45
letbox=[]
6+
// loop i over 0-8
57
for(leti=0;i<=8;i++){
8+
// loop j over 0-8
69
for(letj=0;j<=8;j++){
10+
// this will help us get position of each cell from board
711
letIndI=3*Math.floor(i/3)+Math.floor(j/3)
812
letIndJ=3*(i%3)+(j%3)
13+
// check if value is already in row , col or box and return false
914
if(row.indexOf(board[i][j])!=-1){returnfalse}
1015
if(col.indexOf(board[j][i])!=-1){returnfalse}
1116
if(box.indexOf(board[IndI][IndJ])!=-1){returnfalse}
12-
17+
// if not then add value to row , col and box
1318
if(board[i][j]!='.'){row.push(board[i][j])}
1419
if(board[j][i]!='.'){col.push(board[j][i])}
1520
if(board[IndI][IndJ]!='.'){box.push(board[IndI][IndJ])}
1621
}
22+
// reset row , col and box array
1723
row=[]
1824
col=[]
1925
box=[]
2026
}
2127

2228
returntrue
23-
}
29+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp