+1 vote
by
There is an array. Need to find duplicate values by subarray for the second element (where in my example numbers)
[
['a', 123, 'test'],
['a', 100, 'test'],
['rrr', 123, 'tt'],
['rrr', 9, 'tt'],
['b', 9, 'a'],
]
on the way out:[123, 9] How to make it short and beautiful? Wouldn't the lodash help?

1 Answer

0 votes
by
 
Best answer
const getDuplicatedValues = (arr, key) => Array
.from(arr.reduce((acc, { [key]: n }) => acc.set(n, 1 + (acc.get(n) || 0)), new Map))
.filter(n => n[1] > 1)
.map(n => n[0]);
...