Good day! Stumbled upon such a way to compare two arrays
a1.length==a2.length && a1.every((v,i)=> v === a2[i]) Can you please tell me how to adapt it for comparing two two-dimensional arrays?
Good day! Stumbled upon such a way to compare two arrays
a1.length==a2.length && a1.every((v,i)=> v === a2[i]) Can you please tell me how to adapt it for comparing two two-dimensional arrays?
In javascript no two-dimensional arrays. There are arrays consisting of arrays. Well, that and adapt
function isEqualArray1(a1, a2) { return a1.length === a2.length && a1.every((v,i)=> v === a2[i]); } function isEqualArray2(a1, a2) { return a1.length === a2.length && a1.every((v,i)=> isEqualArray1(v, a2[i])); } No length comparison
a1.every((v,i) => a1[i].every((v,j) => v === a2[i][j])) Source: https://ru.stackoverflow.com/questions/776711/
All Articles