Skip to content

Instantly share code, notes, and snippets.

@chase-lambert
Last active January 21, 2024 17:21
Show Gist options
  • Save chase-lambert/d5db3873cb3f1eee90bc5ebf6b664c97 to your computer and use it in GitHub Desktop.
Save chase-lambert/d5db3873cb3f1eee90bc5ebf6b664c97 to your computer and use it in GitHub Desktop.
rendezvous with cassidoo challenge: 24.01.15
pub enum Direction {
Horizontal,
Vertical,
}
pub fn flip<T>(arr: Vec<Vec<T>>, direction: Direction) -> Vec<Vec<T>> {
match direction {
Direction::Horizontal => arr
.into_iter()
.map(|row| row.into_iter().rev().collect())
.collect(),
Direction::Vertical => arr.into_iter().rev().collect(),
}
}
#[test]
fn test_flip_horizontal() {
let array = vec![vec![1, 2, 3], vec![4, 5, 6], vec![7, 8, 9]];
let expected = vec![vec![3, 2, 1], vec![6, 5, 4], vec![9, 8, 7]];
assert_eq!(flip(array, Direction::Horizontal), expected);
}
#[test]
fn test_flip_vertical() {
let array = vec![vec![1, 2, 3], vec![4, 5, 6], vec![7, 8, 9]];
let expected = vec![vec![7, 8, 9], vec![4, 5, 6], vec![1, 2, 3]];
assert_eq!(flip(array, Direction::Vertical), expected);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment