Search for matrix inside another matrix in Js

Asked

Viewed 36 times

1

I wonder if it is possible to identify if a matrix is inside another javascript matrix.

inserir a descrição da imagem aqui

For example, if the matrix A is inside B or C inside A.

I’m trying to apply the following code:

a = [[1,2],[5,4]]

c = [[2,4],[10,8], [1, 2], [5,4]]

function compare(first, last)
{
    var result = first.filter(function(item){ return last.indexOf(item) > -1});   
    return result.length;  
}    

console.log(compare(a, c) === a.length);
  • In this case you want to compare if two matrices are equal, no? Although your code does not reflect the image. Where the matrix B in the code?

  • in the case I did I wouldn’t have B, but A is inside C

  • In this case then you want to return a boolean (true or false) according to the query "a is inside c"?

  • that’s right, that would be the answer

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.