Menu
Coddy logo textTech

Recap - Reversed Array

Part of the Fundamentals section of Coddy's Rust journey — lesson 63 of 75.

challenge icon

Challenge

Easy

Write a function named rev_arr which gets an array of length 8 of i32 as argument and returns the reversed array.

For example, for [1, 2, 3], the expected output is [3, 2, 1].

Try it yourself

use std::io;
use std::convert::TryInto;

fn rev_arr(arr: &[i32]) -> [i32; 8] {
    // Write your code below
   
}

fn main() {
    let mut input_str_arr = String::new();
    io::stdin().read_line(&mut input_str_arr).unwrap();
    let numbers: [i32; 8] = input_str_arr.trim().split(',').map(|s| s.parse::<i32>().unwrap()).collect::<Vec<i32>>().try_into().unwrap();
    let result = rev_arr(&numbers);
    println!("The reversed array is: {:?}", result);
}

All lessons in Fundamentals