Skip to content

difference

Returns the elements of a that are not in b, in a’s order.

Duplicates in a are kept: only membership in b decides whether an element stays.

use helpers4::array::difference;

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 difference<T: Clone + Eq + Hash>(a: &[T], b: &[T]) -> Vec<T>
ParameterTypeDescription
a&[T]The elements to keep from.
b&[T]The elements to remove.

Vec<T>

use helpers4::array::difference;

assert_eq!(difference(&[1, 2, 3, 2], &[2]), vec![1, 3]);
assert_eq!(difference(&[1, 1, 2], &[3]), vec![1, 1, 2]);

src/array/difference.rs