Filters out the unique values in a list.
Use Iterable.where()
in combination with List.indexOf()
and List.lastIndexOf()
to filter out the unique values.
代码实现
List<T> filterUnique<T>(List<T> lst) {
return lst.where((i) => lst.indexOf(i) != lst.lastIndexOf(i)).toList();
}
使用样例
filterUnique([1, 2, 2, 3, 4, 4, 5]); // [2, 2, 4, 4]