pubfnspin_words(input:&str)->String{input.split(" ").map(|word|{ifword.len()>=5{word.chars().rev().collect()}else{word.to_string()}}).collect::<Vec<String>>().join(" ")}#[cfg(test)]modtests{usecrate::*;#[test]fnit_works_for_words_shorter_than_4_chars(){assert_eq!(spin_words("Test"),"Test".to_string());assert_eq!(spin_words("Te"),"Te".to_string());assert_eq!(spin_words("ant"),"ant".to_string());assert_eq!(spin_words("lots of tiny word"),"lots of tiny word".to_string());}#[test]fnit_words_for_the_example(){assert_eq!(spin_words("Stop gninnipS My sdroW"),"Stop Spinning My Words".to_string());}#[test]fnit_words_with_space_padded_strings(){assert_eq!(spin_words(" Stop gninnipS My sdroW ")," Stop Spinning My Words ".to_string());}}
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.
Here is my Rust solution and test cases!
The Rust std lib made this one pretty simple!