Suppose I have 2 string arrays from different sources and I want to check if both of them have any values in common, what would be the best approach in Typescript. What would be even better is, if we could find a degree of likeness between them.
Of-course looping through each elements and comparing them individually would work, but I'm looking for a more efficient approach.
- Consider values in array to be unique
- Let's assume they're strings for this example. But even if they're custom objects, they would have an inherent "compare" method to check equality.
- Degree of likeness : If all values match then 100% ; if half of the values match 50% . For eg: ["a","b"] and ["a"] would return 50 %. For 100% match, the number of items in both arrays will also have to be same.
And thanks in advance!!