Compare elements of an array in javascript

0

I would like to know how to compare the rows of a matrix. This is in order to verify if the rows all the elements of the row are multiples of themselves. It is clear to me that one number is multiple of another when the result of its module is 0. Now, my problem is that we say that I have this matrix

So let's say that I want to compare the first row that has the numbers 4 and 8, obviously they are multiples, like the second.

Any ideas please?

Thank you!

    
asked by Julio Guzman 04.03.2018 в 03:17
source

2 answers

1

The easiest way is to create two iterations (for) that give you the combinations of two rows to compare ...

Once you have the two rows then you need another for to compare the elements and move in each of the positions in order to try e1 % e%2 == 0

    
answered by 04.03.2018 в 03:34
1

It would be something like this:
var miArray = [[4,5],[8,10]];
for(i=0; i<miArray.length; i++){ if((miArray[i][1]%miArray[i][0])==0){ alert(miArray[i][1]+" es muñtiplo de "+miArray[i][0]); } else { alert(miArray[i][1]+" no es muñtiplo de "+miArray[i][0]); } }

    
answered by 04.03.2018 в 04:38