Consider this array:
var selection = ["14-3","19-5", "23-5", "40-8", "41-8"];
We now have two separate arrays: Array1 includes the first part of each value (before hyphens) in the original array, such as 19, 23, etc. Array2 includes the second parts - 5, 8, etc.
Array1 = ["23", "40"]
Array2 = ["5", "8"]
The goal is to filter out certain elements from the selection array based on the following criteria:
- Exclude any items where none of the values match those in Array2
- For items where there is a match with any value in Array2, only include those that also match the corresponding value in Array1
In this scenario, the resulting filtered array would look like this:
filteredSelection = ["14-3", "23-5", "40-8"]
While filtering an array by another using .filter() is straightforward, this specific case presents a challenge. Any assistance would be greatly appreciated.