solved in rust made with tests first :)
pub fn alphabet_position(s: &str) -> String { s.to_lowercase() .chars() .filter(|x| x.is_alphabetic()) .map(|x| -> u8 { x as u8 - 'a' as u8 + 1 }) .map(|x| -> String { x.to_string() }) .collect::<Vec<String>>() .join(" ") } #[cfg(test)] mod test { use super::*; #[test] fn it_should_relace_the_a_with_1() { let replaced = alphabet_position("a"); assert_eq!(replaced, "1"); } #[test] fn it_should_relace_the_capital_a_with_1() { let replaced = alphabet_position("A"); assert_eq!(replaced, "1"); } #[test] fn it_should_ignore_non_characters() { let replaced = alphabet_position("'a a. 2"); assert_eq!(replaced, "1 1"); } #[test] fn it_should_relace_the_sentence() { let replaced = alphabet_position("The sunset sets at twelve o' clock."); assert_eq!( replaced, "20 8 5 19 21 14 19 5 20 19 5 20 19 1 20 20 23 5 12 22 5 15 3 12 15 3 11" ); } }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
solved in rust made with tests first :)