let big_coordinates_arr =[ [1,2],[3,4],[5,8],[7,9]] ;
let small_coordinates_arr=[ [3,4],[7,9] ] ;
Exepected Output: [ [1,2],[5,8] ]
Dear all, is there a way to filter an array of coordinates from an array of coordinates? There are codes similar to this from element of array at here, but I am unsure on filtering 2d-nested array.
I will appreciate if anyone can guide me 🙂
3
Answers
Try this one.
But this solution works if you want to exclude all matched elements. I mean, if
big_coordinates_arr
has[3,4]
element twice or more, this algorithm eliminates all of them.Another solution using
Array.filter()
andArray.every()
to do itYou can convert the coordinates into string for easier comparison. Then just filter the strings our from the big_cordinates. 🙂