pub fn drop_right<T>(collection: &[T], n: usize) -> Vec<T>where
T: Clone,Expand description
Removes the last n elements from a collection and returns the remaining elements.
If n is greater than or equal to the length of the collection, returns an empty Vec.
Time Complexity: O(1) for slicing; O(m) for cloning, where m is the number of elements after dropping.
§Arguments
collection- A slice of items from which elements will be dropped.n- The number of elements to drop from the end of the collection.
§Type Parameters
T- The type of elements in the collection. Must implementClone.
§Returns
Vec<T>- A vector containing the elements after dropping the lastnelements.
§Examples
use lowdash::drop_right;
let numbers = vec![1, 2, 3, 4, 5];
let result = drop_right(&numbers, 2);
assert_eq!(result, vec![1, 2, 3]);use lowdash::drop_right;
let letters = vec!['a', 'b', 'c', 'd'];
let result = drop_right(&letters, 10);
assert_eq!(result, vec![]);