permutation

Function permutation 

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

Finds all permutations of k elements from a collection.

§Arguments

  • items - A slice of items to permute.
  • k - The number of elements in each permutation.

§Returns

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

§Examples

use lowdash::permutation;

let items = vec![1, 2, 3];
let result = permutation(&items, 2);
// Expected permutations: [ [1,2], [1,3], [2,1], [2,3], [3,1], [3,2] ]
assert_eq!(result.len(), 6);
assert!(result.contains(&vec![2, 1]));