1var array = [1, 2, 2, 3, 3, 4, 5, 6, 2, 3, 7, 8, 5, 22, 1, 2, 511, 12, 50, 22];
2
3console.log([...new Set(
4 array.filter((value, index, self) => self.indexOf(value) !== index))]
5);
1const names = ['Mike', 'Matt', 'Nancy', 'Adam', 'Jenny', 'Nancy', 'Carl']
2
3const count = names =>
4 names.reduce((a, b) => ({ ...a,
5 [b]: (a[b] || 0) + 1
6 }), {}) // don't forget to initialize the accumulator
7
8const duplicates = dict =>
9 Object.keys(dict).filter((a) => dict[a] > 1)
10
11console.log(count(names)) // { Mike: 1, Matt: 1, Nancy: 2, Adam: 1, Jenny: 1, Carl: 1 }
12console.log(duplicates(count(names))) // [ 'Nancy' ]