combination

Function combination 

Source
pub fn combination<T: Clone>(items: &[T], k: usize) -> Vec<Vec<T>>
Expand description

Finds all combinations of k elements from a collection.

§Arguments

  • items - A slice of items to combine
  • k - The number of elements to select in each combination

§Returns

  • Vec<Vec<T>> - A vector containing all combinations of k elements from the input

§Examples

use lowdash::combination;

let items = vec![1, 2, 3, 4];
let result = combination(&items, 2);
assert_eq!(result.len(), 6);
// One possible combination: [2, 3]
assert!(result.contains(&vec![2, 3]));