小编alf*_*_JS的帖子

Rust关于Vec的Reduce方法参考

我正在尝试将 Vec 的引用减少到其总和,以便我可以计算其平均值。不过,我遇到了编译器问题,并且我没有遵循如何不正确借用/引用事物的情况。

// Given a list of integers, use a vector and return the mean (the average value), median (when sorted, the value in the middle position), and mode (the value that occurs most often; a hash map will be helpful here) of the list.
fn main() {
    let list_of_integers = vec![200, -6_000, 3, 0, 23, 99, -1];

    let mean_ans = mean(&list_of_integers);
    // Other code that will also use list_of_integers hence why I want to reference list_of_integers so it …
Run Code Online (Sandbox Code Playgroud)

functional-programming reference rust rust-cargo borrow-checker

4
推荐指数
2
解决办法
6730
查看次数