Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
The key is line 3. If we just wanted ALL matches, we could just return arr.indexOf(val) !== arr.lastIndexOf(val) as that gives us, for example, ALL duplicate occurrences of "b" or "i" or whatever in the array.
However, the problem asks us to only return distinct duplicates, so we can't use the common pattern of indexOf !== lastIndexOf. We have to be a bit more clever than that.
In order to filter down to a distinct duplicate of the current index item, we essentially just want to return the last occurrence of the duplicate. The filter has to skip over duplicate values that have already been matched and find the last one.
Specifically we only want to return the current val in the filter/loop if (1) indexOf(val) has already appeared in the array but is not the current occurrence of val that we are looking at (arr.indexOf(val) !== i) AND (2) lastIndexOf(val) is the current occurrence (arr.lastIndexOf(val) === i).
What more do you need? That's already there and it seems clear enough imo.
That's a problem with your code, not a kata issue: