Skip to content

Commit 19f2d4c

Browse files
authored
Create deepCompare.js
1 parent 4ecc4a1 commit 19f2d4c

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

deepCompare_7/deepCompare.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//deep comparison of multi-dimensional arrays with recursion
2+
3+
const deepCompare = (a, b) => {
4+
let res = true
5+
6+
if(Array.isArray(a) && Array.isArray(b))
7+
{
8+
let count = 0;
9+
10+
while(res && count < a.length)
11+
{
12+
res = !a.some( (val, i) => {
13+
return !deepCompare(val, b[i])
14+
})
15+
16+
count++
17+
}
18+
}
19+
else
20+
{
21+
res = (a === b)
22+
}
23+
24+
return res
25+
26+
}

0 commit comments

Comments
 (0)