diff --git a/rust/tests/4_create_phone_number.rs b/rust/tests/4_create_phone_number.rs index c4ec151..d492a89 100644 --- a/rust/tests/4_create_phone_number.rs +++ b/rust/tests/4_create_phone_number.rs @@ -1,6 +1,19 @@ +const PHONE_MASK: &str = "(___) ___-____"; +const ZERO: u8 = '0' as u8; + fn create_phone_number(numbers: &[u8]) -> String { - let numbers = numbers.iter().map(|i| i.to_string()).collect::(); - format!("({}) {}-{}", &numbers[..3], &numbers[3..6], &numbers[6..]) + let mut position = 0; + PHONE_MASK + .chars() + .map(|c| match c { + '_' => { + let c = (numbers[position] + ZERO) as char; + position += 1; + c + } + c => c, + }) + .collect() } #[test]