fn likes(names: &[&str]) -> String { match names { [] => format!("no one likes this"), [a] => format!("{} likes this", a), [a, b] => format!("{} and {} like this", a, b), [a, b, c] => format!("{}, {} and {} like this", a, b, c), [a, b, rest @ ..] => format!("{}, {} and {} others like this", a, b, rest.len()), } } #[test] fn fixed_tests() { assert_eq!(likes(&[]), "no one likes this"); assert_eq!(likes(&["Peter"]), "Peter likes this"); assert_eq!(likes(&["Jacob", "Alex"]), "Jacob and Alex like this"); assert_eq!( likes(&["Max", "John", "Mark"]), "Max, John and Mark like this" ); assert_eq!( likes(&["Alex", "Jacob", "Mark", "Max"]), "Alex, Jacob and 2 others like this" ); assert_eq!( likes(&["a", "b", "c", "d", "e"]), "a, b and 3 others like this" ); }