Filters out the non-unique values in an array.

Use Array.prototype.filter() for an array containing only the unique values.

代码片段

const filterNonUnique = arr => arr.filter(i => arr.indexOf(i) === arr.lastIndexOf(i));

使用样例

filterNonUnique([1, 2, 2, 3, 4, 4, 5]); // [1, 3, 5]