Skip to content

Instantly share code, notes, and snippets.

@eightbitraptor
Created June 23, 2014 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eightbitraptor/2d33d1dd9a3c68478f94 to your computer and use it in GitHub Desktop.
Save eightbitraptor/2d33d1dd9a3c68478f94 to your computer and use it in GitHub Desktop.
fn last_but_one(list: Vec<int>) -> Option<int> {
println!("{}", list.reverse());
match list.is_empty() {
true => { None }
false => { list.reverse().get(1) }
};
}
#[test]
fn test_last_but_one_with_empty_list() {
assert_eq!(last_but_one(Vec::<int>::new()), None)
}
#[test]
fn test_gets_penultimate_element() {
assert_eq!(last_but_one(vec!(1, 5, 6, 7, 2, 4)), Some(2));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment