So, I have an array
['a', 42, 'b', 42, 'a']
I want to alert users to the fact that 42 and 'a' appear in it twice.
some_function(['a', 42, 'b', 42, 'a'])
Write some code to extract the duplicates from an array.
- It should accept an array as input.
- The array can have multiple types of object.
- Duplication should be defined as per the language's standard equality function (examples are from ruby).
- It outputs an array of the duplicated items.
- The order of the returned items is irrelevant.
- Duplicates should only appear in the returned array once.
- Golf rules, do it in the smallest number of bytes.
[1,2,3] =>  [1,2,3,2,1] => [1,2] [1.0, 2, 2.0, 1.0] => [1, 2] or [1.0, 2.0] or [1, 2.0] or [1.0, 2] [1, '1', '1.0'] =>  [nil, nil, false, false, true, true] => [nil, false, true]