array-functions
A Rust crate providing useful array manipulation utilities and statistical functions for everyday programming needs.
Features
- Array manipulation utilities
- Split vectors into chunks
- Remove duplicates from arrays
- Find pairs that sum to a target value
- Statistical functions
- Calculate mean (average)
- Calculate median
- Calculate mode
Installation
Add this to your Cargo.toml:
[]
= "0.1.0" # Replace with your current version
Usage
Array Utilities
use ;
Statistical Functions
use ;
API Documentation
Array Utilities
-
chunk_vec<T: Clone>(vec: &[T], chunk_size: usize) -> Result<Vec<Vec<T>>, &'static str>- Splits a vector into chunks of specified size
- Returns an error if chunk_size is zero
-
remove_duplicates<T: Clone + PartialEq>(vec: &[T]) -> Vec<T>- Removes duplicate elements while preserving order
-
find_pairs_with_sum<T: Copy + Hash + Eq + Sub<Output = T>>(arr: &[T], target: T) -> Vec<(T, T)>- Finds all pairs of numbers that sum to the target value
Statistical Functions
-
mean(vec: &[f64]) -> f64- Calculates the arithmetic mean of a vector of numbers
-
median(vec: &[f64]) -> f64- Calculates the median value of a vector of numbers
-
mode(vec: &[i32]) -> i32- Calculates the mode (most frequent value) of a vector of integers
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
This crate was created as a learning project to better understand Rust and contribute to the Rust ecosystem.