Error while calculating Getting average of chunks

I’ve a series of elements, that I need to divide them into chunks of 12, then calculate the average of each chunk, I wrote the below code, but got error:

error[E0282]: type annotations needed
–> src/
20 | .map(|chunk| chunk.iter().sum() as f32/ chunk.len() as f32)
| ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for S

error: aborting due to previous error


fn main() {
    let series = [30,21,29,31,40,48,53,47,37,39,31,29,17,9,20,24,27,35,41,38,

    find_chunks_averages(&series, 12);

fn find_chunks_averages(series: &[i32], chunk_length: i32){
    let _season_averages = series.to_vec();

    let _chunks = series
            .chunks(chunk_length as usize)

    let _chunks_averages= _chunks
            .map(|chunk| chunk.iter().sum() as f32/ chunk.len() as f32)

        println!("The chunks you have are:: {:#?}", _chunks);
        println!("The averagesof the chunks are: {:#?}", _chunks_averages);

The S come from sum.
You just need to add the qualifier like used in other parts of the code;

1 Like