drop

Function drop 

Source
pub fn drop<T>(collection: &[T], n: usize) -> Vec<T>
where T: Clone,
Expand description

Removes the first 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 slices, as it creates a slice from an existing slice.
O(m) for cloning elements, 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 beginning of the collection.

§Type Parameters

  • T - The type of elements in the collection. Must implement Clone.

§Returns

  • Vec<T> - A vector containing the elements after dropping the first n elements.

§Examples

use lowdash::drop;

let numbers = vec![1, 2, 3, 4, 5];
let result = drop(&numbers, 2);
assert_eq!(result, vec![3, 4, 5]);
use lowdash::drop;

let letters = vec!['a', 'b', 'c', 'd'];
let result = drop(&letters, 10);
assert_eq!(result, vec![]);