forked from TrendingTechnology/JavaScript-Coding-Practice
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwordSquare.js
More file actions
35 lines (30 loc) · 648 Bytes
/
Copy pathwordSquare.js
File metadata and controls
35 lines (30 loc) · 648 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const validWordSquare = (words) => {
if (words == null || words.length === 0) {
return false;
}
if (words.length !== words[0].length) {
return false;
}
for (let i = 0; i < words.length; i++) {
for (let j = 0; j < words[i].length; j++) {
if (words[i][j] !== words[j][i]) {
return false;
}
}
}
return true;
};
let arr = [
["b","a","l","l"],
["a","r","e","a"],
["r","e","a","d"],
["l","a","d","y"]
];
let arr1 = [
["a","b","c","d"],
["b","n","r","t"],
["c","r","m","y"],
["d","t","y","e"]
];
console.log(validWordSquare(arr)); // false
console.log(validWordSquare(arr1)); // true