I have 2 arrays of string objects.
let count = 0;
var basket1 = [‘Apples’, ‘Cucumber’, ‘Lettuce’, ‘Bananas’, ‘Pears’, ‘Cauliflower’, ‘Strawberry’]
var basket2 = [‘Apples’, ‘Bananas’, ‘Oranges’, ‘Pears’, ‘Pineapple’, ‘Strawberry’]
When there is an item in a basket1 and basket2 that is the same, I want to increment count.
Note: the length of basket1 and basket2 can vary such that basket1.length > basket2.length, basket1.length < basket2.length or basket1.length = basket2.length,
I was thinking:
- Loop through basket with
basket.forEach( (item) => {} ) - forEach item, if
otherBasket.includes(item), count++
I was just wondering if there was a more efficient way of doing this.