feat(rust): add create phone number kata

This commit is contained in:
Dmitriy Pleshevskiy 2021-10-29 17:52:16 +03:00
parent 0c2f6e04a5
commit 0ba20655f0

View file

@ -0,0 +1,20 @@
fn create_phone_number(numbers: &[u8]) -> String {
let numbers = numbers.iter().map(|i| i.to_string()).collect::<String>();
format!("({}) {}-{}", &numbers[..3], &numbers[3..6], &numbers[6..])
}
#[test]
fn returns_expected() {
assert_eq!(
create_phone_number(&[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]),
"(123) 456-7890"
);
assert_eq!(
create_phone_number(&[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
"(111) 111-1111"
);
assert_eq!(
create_phone_number(&[1, 2, 3, 4, 5, 6, 7, 8, 9, 9]),
"(123) 456-7899"
);
}