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);
1arr.reduce((b,c)=>((b[b.findIndex(d=>d.el===c)]||b[b.push({el:c,count:0})-1]).count++,b),[]);
1const findDuplicates = (nums) => {
2 nums.sort(); // alters original array
3 let ans = []
4
5 for(let i = 0; i< nums.length; i++){
6 if(nums[i] === nums[i+1]){
7 if(ans[ans.length -1] !== nums[i]){
8 ans.push(nums[i])
9 }
10 }
11 }
12 return ans;
13}
14