let big_coordinates_arr =[ [1,2],[3,4],[5,8],[7,9]] ;
let small_coordinates_arr=[ [3,4],[7,9] ] ;
let is_same = (arr1,arr2) => arr1.length == arr2.length && arr1.every(function(element, index) {
return element === arr2[index];
});
let result = big_coordinates_arr.filter(c1 => !small_coordinates_arr.some(c2 => is_same(c1,c2)))
console.log(result)
let big_coordinates_arr =[ [[1,2],[3,4]], [[3,4],[1,2]] , [[5,8],[7,9]] , [[7,1],[6,5]] , [3,6],[7,3] ] ;
let small_coordinates_arr=[ [[3,4],[1,2]] , [[7,1],[6,5]] ] ;
Expected output should be [ [[5,8],[7,9]] , [3,6],[7,3] ]
The code snippet shows the filter output of the coordinates array from another coordinates array.
My question is about filtering a segment array from another segment array. In my example, I have this [[1,2],[3,4]]
which represents a segment (2 points), which means that [[1,2],[3,4]]
and [[3,4],[1,2]]
can be assumed to be the same because you can interchange the 2 points and still form the same segment.
May I ask how to produce the expected output?
I will really appreciate any help I can get:)
2
Answers
By sorting the arrays and all their nested arrays, you’ll be able to achieve the expected output,
I have done multiple tests and then after I get the below response.
Hope you will get an answer.