Skip to content

duplicates

Returns the elements that appear more than once in items, each one once, in the order they first appear.

The counterpart of unique: what unique keeps, this reports as repeated.

use helpers4::array::duplicates;

Cargo feature array (enabled by default). To compile only this module:

cargo add helpers4 --no-default-features --features array

or in Cargo.toml:

[dependencies]
helpers4 = { version = "0.0.5", default-features = false, features = ["array"] }
pub fn duplicates<T: Clone + Eq + Hash>(items: &[T]) -> Vec<T>
ParameterTypeDescription
items&[T]The elements to scan.

Vec<T>

use helpers4::array::duplicates;

assert_eq!(duplicates(&[1, 2, 3, 2, 1, 2]), vec![1, 2]);
assert_eq!(duplicates(&["a", "b", "c"]), Vec::<&str>::new());

src/array/duplicates.rs