Answers for "Rust Options Some None using for loop iteratively"

0

Rust Options Some None using for loop iteratively

fn find_break(arr: &Vec<i32>) -> Option<i32> {
  for i in 1..arr.len() {
    if arr[i] - arr[i - 1] != 1 {
      return Some(arr[i]);
    }
  };
  None
}

fn main() {
    println!("{}", match find_break(&vec![1, 3, 4, 5, 6, 7, 8]) {
        Some(s) => s,
        None => -1
    });
}
//Rust Options Some None using for loop iteratively
Posted by: Guest on February-22-2021

Browse Popular Code Answers by Language