pub fn drop_by_index<T>(collection: &[T], indexes: &[isize]) -> Vec<T>where
T: Clone,Expand description
Removes elements from a collection at the specified indices. Supports negative indices which count from the end of the collection. Indices that are out of bounds are ignored.
Time Complexity: O(n log n) for sorting the indices, O(m) for cloning, where m is the length of the resulting collection.
§Arguments
collection- A slice of items from which elements will be removed.indexes- A slice of indices at which elements should be removed.
§Type Parameters
T- The type of elements in the collection. Must implementClone.
§Returns
Vec<T>- A vector containing the elements after removing the specified indices.
§Examples
use lowdash::drop_by_index;
let numbers = vec![1, 2, 3, 4, 5];
let result = drop_by_index(&numbers, &[1, 3]);
assert_eq!(result, vec![1, 3, 5]);use lowdash::drop_by_index;
let letters = vec!['a', 'b', 'c', 'd', 'e'];
let result = drop_by_index(&letters, &[0, -1]);
assert_eq!(result, vec!['b', 'c', 'd']);